From debae11988586d360901a1f631b82dc61269d59e Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 28 Apr 2023 23:37:14 +0200 Subject: Map Alt+(h/j/k/l) in command mode to move directional --- lua/user/keys.lua | 82 +++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/lua/user/keys.lua b/lua/user/keys.lua index 4b6e9ef..c0592da 100644 --- a/lua/user/keys.lua +++ b/lua/user/keys.lua @@ -1,5 +1,4 @@ --[[ key.lua ]] - ------------- Shorten Function Names -------------- local keymap = vim.keymap local map = function(mode, l, r, opts) @@ -10,7 +9,6 @@ local map = function(mode, l, r, opts) end local term_opts = { noremap = true, silent = false } - --------------- Standard Operations --------------- -- Semi-colon as leader key vim.g.mapleader = ";" @@ -25,7 +23,8 @@ vim.g.mapleader = ";" map("i", "jj", "") -- Reload nvim config -map("n", "", "luafile ~/.config/nvim/init.lua | :echom ('Nvim config loading...') | :sl! | echo ('')") +map("n", "", + "luafile ~/.config/nvim/init.lua | :echom ('Nvim config loading...') | :sl! | echo ('')") --------------- Extended Operations --------------- @@ -35,15 +34,15 @@ map('n', 'q', function() if config.relative ~= "" then -- is_floating_window? return ":silent! close!" elseif - vim.o.buftype == 'quickfix' then + vim.o.buftype == 'quickfix' then return ":quit" elseif - vim.o.buftype == 'help' then + vim.o.buftype == 'help' then return ":close" else return "q" end -end, {expr = true, replace_keycodes = true}) +end, { expr = true, replace_keycodes = true }) -- Combine buffers list with buffer name map("n", "b", ":buffers:buffer") @@ -99,16 +98,10 @@ map("i", "", "") map("i", "", "") -- Map Alt+(h/j/k/l) in command mode to move directional -map("c", "", "") -map("c", "", "") -map("c", "", "") -map("c", "", "") - --- Map Alt+(h/j/k/l) in selection mode to move directional -map("s", "", "") -map("s", "", "") -map("s", "", "") -map("s", "", "") +vim.api.nvim_set_keymap('c', '', '', { noremap = true }) +vim.api.nvim_set_keymap('c', '', '', { noremap = true }) +vim.api.nvim_set_keymap('c', '', '', { noremap = true }) +vim.api.nvim_set_keymap('c', '', '', { noremap = true }) -- Create tab, edit and move between them map("n", "n", ":tabnew") @@ -179,13 +172,13 @@ map('n', 'o', ':!xdg-open %') -- URL handling if vim.fn.has("mac") == 1 then - map("", "gx", 'call jobstart(["open", expand("")], {"detach": v:true})', {}) + map("", "gx", 'call jobstart(["open", expand("")], {"detach": v:true})', {}) elseif vim.fn.has("unix") == 1 then - map("", "gx", 'call jobstart(["xdg-open", expand("")], {"detach": v:true})', {}) + map("", "gx", 'call jobstart(["xdg-open", expand("")], {"detach": v:true})', {}) elseif vim.fn.has("wsl") == 1 then - map("", "gx", 'call jobstart(["wslview", expand("")], {"detach": v:true})', {}) + map("", "gx", 'call jobstart(["wslview", expand("")], {"detach": v:true})', {}) else - map[''].gx = {'lua print("Error: gx is not supported on this OS!")'} + map[''].gx = { 'lua print("Error: gx is not supported on this OS!")' } end -- Toggle completion @@ -197,15 +190,15 @@ map('i', '', '') -- Set line wrap map("n", "", function() - local wrap_status = vim.api.nvim_exec("set wrap ?", true) - - if wrap_status == "nowrap" then - vim.api.nvim_command("set wrap linebreak") - print("Wrap enabled") - else - vim.api.nvim_command("set wrap nowrap") - print("Wrap disabled") - end + local wrap_status = vim.api.nvim_exec("set wrap ?", true) + + if wrap_status == "nowrap" then + vim.api.nvim_command("set wrap linebreak") + print("Wrap enabled") + else + vim.api.nvim_command("set wrap nowrap") + print("Wrap disabled") + end end, { silent = true }) -- Toggle between folds @@ -251,7 +244,7 @@ map('n', '', 'NavigatorDown') --map("n", "tt", "ToggleTerm") -- LazyGit -map({"n", "t"}, "gg", "lua Lazygit_toggle()") +map({ "n", "t" }, "gg", "lua Lazygit_toggle()") -- Fugitive git bindings map("n", "ga", ":Git add %:p") @@ -284,7 +277,7 @@ map("n", "gm", ":Gmove") -- Telescope map("n", "ff", function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end) -- find all files -map("n", "fF", "lua require('telescope.builtin').find_files()") -- find files with hidden option +map("n", "fF", "lua require('telescope.builtin').find_files()") -- find files with hidden option map("n", "fg", "lua require('telescope.builtin').live_grep()") map("n", "fb", "lua require('telescope.builtin').buffers()") map("n", "fh", "lua require('telescope.builtin').help_tags()") @@ -295,13 +288,13 @@ map("n", "fp", "Telescope pickers") map("n", "fr", "lua require('telescope.builtin').registers({})") -- registers picker map("n", "fd", "lua require('telescope.builtin').diagnostics()") map("n", "fk", "lua require('telescope.builtin').keymaps()") -map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) -- find notes -map("n", "fgn", [[lua require'plugins.telescope'.grep_notes()]]) -- search notes -map("n", "f.", [[lua require'plugins.telescope'.find_configs()]]) -- find configs -map("n", "fs", [[lua require'plugins.telescope'.find_scripts()]]) -- find scripts -map("n", "fw", [[lua require'plugins.telescope'.find_projects()]]) -- find projects +map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) -- find notes +map("n", "fgn", [[lua require'plugins.telescope'.grep_notes()]]) -- search notes +map("n", "f.", [[lua require'plugins.telescope'.find_configs()]]) -- find configs +map("n", "fs", [[lua require'plugins.telescope'.find_scripts()]]) -- find scripts +map("n", "fw", [[lua require'plugins.telescope'.find_projects()]]) -- find projects map("n", "fm", "lua require('telescope').extensions.media_files.media_files({})") -- find media files -map("n", "fi", "lua require('telescope').extensions.notify.notify({})") -- find notifications +map("n", "fi", "lua require('telescope').extensions.notify.notify({})") -- find notifications -- FZF map("n", "fz", "lua require('fzf-lua').files()") @@ -335,12 +328,12 @@ map('n', 'qr', ':lua require("replacer").run()') -- Quickfix map("n", "q", function() - if vim.fn.getqflist({ winid = 0 }).winid ~= 0 then - require('plugins.quickfix').close() - else - require('plugins.quickfix').open() - --require("quickfix").open() - end + if vim.fn.getqflist({ winid = 0 }).winid ~= 0 then + require('plugins.quickfix').close() + else + require('plugins.quickfix').open() + --require("quickfix").open() + end end, { desc = "Toggle quickfix window" }) -- Dap (debugging) @@ -348,7 +341,7 @@ local dap_ok, dap = pcall(require, "dap") local dap_ui_ok, ui = pcall(require, "dapui") if not (dap_ok and dap_ui_ok) then - require("notify")("nvim-dap or dap-ui not installed!", "warning") + require("notify")("nvim-dap or dap-ui not installed!", "warning") return end @@ -387,4 +380,3 @@ map("n", "", "Dashboard") -- Lsp Lines toggle map("", "l", require("lsp_lines").toggle, { desc = "Toggle lsp_lines" }) - -- cgit v1.2.3