diff --git a/home/dot_config/lvim/lua/user/functions.lua b/home/dot_config/lvim/lua/user/functions.lua index 1ad9621..3576ed9 100644 --- a/home/dot_config/lvim/lua/user/functions.lua +++ b/home/dot_config/lvim/lua/user/functions.lua @@ -8,26 +8,59 @@ Last Modified By : Jeff Lance --- function Surround(w_or_W) --- local open_char = vim.fn.input("Surround with: ") --- local closed_char = nil --- if open_char == "(" then closed_char = ")" end --- if open_char == "[" then closed_char = "]" end --- if open_char == "{" then closed_char = "}" end --- if open_char == "<" then closed_char = ">" end --- if open_char == "'" then closed_char = "'" end --- if open_char == '"' then closed_char = '"' end --- if open_char == "`" then closed_char = "`" end --- if open_char == "/" then closed_char = "/" end --- if open_char == "|" then closed_char = "|" end +local M = {} --- if w_or_W == "w" then --- vim.cmd("normal! ciw" .. open_char) --- elseif w_or_W == "W" then --- vim.cmd([[normal! ciW]] .. open_char) --- end --- vim.cmd("normal! p") --- vim.cmd("normal! a" .. closed_char) --- vim.cmd("normal! a") --- end +--- Get current buffer size +---@return {width: number, height: number} +local function get_buf_size() + local cbuf = vim.api.nvim_get_current_buf() + local bufinfo = vim.tbl_filter(function(buf) + return buf.bufnr == cbuf + end, vim.fn.getwininfo(vim.api.nvim_get_current_win()))[1] + if bufinfo == nil then + return { width = -1, height = -1 } + end + return { width = bufinfo.width, height = bufinfo.height } +end + +--- Get the dynamic terminal size in cells +---@param direction string +---@param size number +---@return integer +local function get_dynamic_terminal_size(direction, size) + size = size or lvim.builtin.terminal.size + if direction ~= "float" and tostring(size):find(".", 1, true) then + size = math.min(size, 1.0) + local buf_sizes = get_buf_size() + local buf_size = direction == "horizontal" and buf_sizes.height or buf_sizes.width + return buf_size * size + else + return size + end +end + +M.xplr_toggle = function() + local Terminal = require("toggleterm.terminal").Terminal + local direction = "float" + + local xplr = Terminal:new { + cmd = "ranger", + hidden = true, + direction = direction, + -- size = 20 | function() + -- return get_dynamic_terminal_size("float", 0.8) + -- end, + float_opts = { + border = "curved", + }, + on_open = function(_) + vim.cmd "startinsert!" + end, + on_close = function(_) end, + count = 200, + } + xplr:toggle() +end + +return M diff --git a/home/dot_config/lvim/lua/user/keybindings.lua b/home/dot_config/lvim/lua/user/keybindings.lua index 8e399a9..4f4f1fb 100644 --- a/home/dot_config/lvim/lua/user/keybindings.lua +++ b/home/dot_config/lvim/lua/user/keybindings.lua @@ -12,11 +12,11 @@ local M = {} M.setup = function() -- ============ - -- key mappings + -- key mappings examples using nvim or lvim api. -- - -- vim-surround shortcuts as example -- vim.api.nvim_set_keymap("n", "sw", "Ysurroundiw", { noremap = true, silent = true }) -- vim.api.nvim_set_keymap("n", "Sw", "YSurroundiw", { noremap = true, silent = true }) + -- lvim.keys.normal_mode[""] = ":FloatermToggle terminal" -- lvim.leader = ";" @@ -28,7 +28,6 @@ M.setup = function() lvim.keys.normal_mode[""] = "redo" lvim.keys.normal_mode[""] = ":<" lvim.keys.normal_mode[""] = ":>" - lvim.keys.normal_mode[""] = ":FloatermNew --name=term --width=0.8" end diff --git a/home/dot_config/lvim/lua/user/luasnip-helper-funcs.lua b/home/dot_config/lvim/lua/user/luasnip-helper-funcs.lua index d812c86..7bbf547 100644 --- a/home/dot_config/lvim/lua/user/luasnip-helper-funcs.lua +++ b/home/dot_config/lvim/lua/user/luasnip-helper-funcs.lua @@ -89,15 +89,15 @@ Last Modified By : Jeff Lance -- local rows = tonumber(snip.captures[2]) -- local cols = tonumber(snip.captures[3]) -- local nodes = {} --- local ins_indx = 1 --- for j = 1, rows do +-- local ins_indx = 1 +-- for j = 1, rows do -- table.insert(nodes, r(ins_indx, tostring(j) .. "x1", i(1))) --- ins_indx = ins_indx + 1 --- for k = 2, cols do +-- ins_indx = ins_indx + 1 +-- for k = 2, cols do -- table.insert(nodes, t(" & ")) --- table.insert(nodes, r(ins_indx, tostring(j) .. "x" .. tostring(k), i(1))) --- ins_indx = ins_indx + 1 --- end +-- table.insert(nodes, r(ins_indx, tostring(j) .. "x" .. tostring(k), i(1))) +-- ins_indx = ins_indx + 1 +-- end -- table.insert(nodes, t({ " \\\\", "" })) -- end -- -- fix last node. diff --git a/home/dot_config/lvim/lua/user/plugins.lua b/home/dot_config/lvim/lua/user/plugins.lua index 9e1db2a..1f3b742 100644 --- a/home/dot_config/lvim/lua/user/plugins.lua +++ b/home/dot_config/lvim/lua/user/plugins.lua @@ -274,6 +274,7 @@ M.setup = function() }) end, }, + -- rnvimr { "kevinhwang91/rnvimr", cmd = "RnvimrToggle", @@ -284,9 +285,9 @@ M.setup = function() let g:rnvimr_edit_cmd = 'drop' let g:rnvimr_draw_border = 1 let g:rnvimr_hide_gitignore = 1 - let g:rnvimr_border_attr = {'fg': 14, 'bg': -1} + " let g:rnvimr_border_attr = {'fg': 14, 'bg': 0} let g:rnvimr_enable_bw = 1 - let g:rnvimr_shadow_winblend = 70 + " let g:rnvimr_shadow_winblend = 70 let g:rnvimr_ranger_cmd = ['ranger', '--cmd=set draw_borders both'] ]]) end, diff --git a/home/dot_config/lvim/lua/user/whichkey.lua b/home/dot_config/lvim/lua/user/whichkey.lua index 5491ac0..a23f75a 100644 --- a/home/dot_config/lvim/lua/user/whichkey.lua +++ b/home/dot_config/lvim/lua/user/whichkey.lua @@ -34,7 +34,7 @@ M.setup = function() } -- remap neo-tree shortcut to rnvimr - lvim.builtin.which_key.mappings["e"] = { "RnvimrToggle", "File explorer" } + -- lvim.builtin.which_key.mappings["e"] = { "RnvimrToggle", "File explorer" } -- remap dashboard lvim.builtin.which_key.mappings["d"] = lvim.builtin.which_key.mappings[";"] @@ -99,6 +99,8 @@ M.setup = function() lvim.builtin.which_key.mappings["x"] = { "w! q!", "Save and quit" } lvim.builtin.which_key.mappings[";"] = {} + -- lvim.builtin.which_key.mappings["e"] = { ":lua require('user.functions').xplr_toggle()", "File manager" } + lvim.builtin.which_key.mappings["e"] = { ":RnvimrToggle", "File manager" } lvim.builtin.terminal.open_mapping = "" end