From de2e9e90f1117e9a5726c8728c2e196d82d61a1f Mon Sep 17 00:00:00 2001 From: Marcelo Jacobus Date: Mon, 30 Jun 2025 10:55:05 -0300 Subject: [PATCH] More mappings --- lua/user/keymaps.lua | 130 +++++++++++++++++++++++- lua/user/options.lua | 5 + old/lua/config/keymaps.lua | 196 ------------------------------------- 3 files changed, 130 insertions(+), 201 deletions(-) delete mode 100644 old/lua/config/keymaps.lua diff --git a/lua/user/keymaps.lua b/lua/user/keymaps.lua index 4628780..3a07960 100644 --- a/lua/user/keymaps.lua +++ b/lua/user/keymaps.lua @@ -26,6 +26,18 @@ map("n", "q", "bdelete", opts) map("n", "bdd", "bdelete!", opts) map("n", "bda", "bufdo %bd!", opts) + +-- Alternate file +map("n", "af", "", { desc = "Alternate file" }) + +-- Avoid arrow keys in command mode +map("c", "", "", { desc = "Move left" }) +map("c", "", "", { desc = "Move down" }) +map("c", "", "", { desc = "Move up" }) +map("c", "", "", { desc = "Move right" }) +map("c", "", "", { desc = "Delete" }) + + -- Notes map("n", "et", ":e ~/.tmp/notes/", opts) map("n", "on", ":e ~/.tmp/notes/notes.md", opts) @@ -38,21 +50,22 @@ map("t", "jj", "", opts) -- Search map("n", "f", "/", opts) map("n", "F", "nohlsearch", opts) +map("n", "*", "*N", { desc = "Search and stay" }) -- Quickfix -map("n", "gn", ":cnext", opts) -map("n", "gp", ":cprev", opts) +map("n", "gn", ":cnext", { desc = "Next quickfix occurrency" }) +map("n", "gp", ":cprev", { desc = "Previous quickfix occurrency" }) + -- Buffer navigation map("n", "bn", ":bn", opts) map("n", "bp", ":bp", opts) map("n", "b", ":b", opts) --- Select all -map("n", "a", "ggVG", opts) +map("n", "a", "ggVG", { desc = "Select all" }) -- Tabs -map("n", "t", ":tabnew", opts) +map("n", "t", ":tabnew", { desc = "New tab" }) -- Insert helpers map("i", ",e", "/[\\]})\"']:nohlsearcha", opts) @@ -70,6 +83,9 @@ map("n", "rel", ":e", opts) -- File finder (stub) map("n", "*", ":find", opts) +map("n", "rm", ":Delete", { desc = "Delete file" }) +map("n", "o", "", { desc = "Last buffer" }) + -- Formatting map("v", "Q", "gq", opts) map("n", "Q", "gqap", opts) @@ -126,3 +142,107 @@ end, { desc = "Run test file" }) map("n", "st", function() require("mj.test_runner").run_shell_test() end, { desc = "Run ./shell_test" }) + + +map("v", "", function() + alternative_file.open("next", "--exists") +end, { desc = "Open next alternative file" }) + +local alternative_file = require("mj.alternate_file") + +map("n", "irc", function() + require("mj.ruby_utils").insert_ruby_class_based_on_file_path() +end, { desc = "Insert ruby class" }) + +-- this is not working correctly +-- map("v", "irc", function() +-- require("mj.ruby_utils").replace_selected_text_with_ruby_class() +-- end, { desc = "Replace selected text ruby class" }) + +map("n", "aj", function() + alternative_file.open("prev", "--exists") +end, { desc = "Open previous alternative file" }) + + +map("n", "j", function() + require("mj.utils").close_terminal_buffer(true) +end, { desc = "Close terminal buffer (true)" }) + +map("n", "k", function() + require("mj.utils").close_terminal_buffer(false) +end, { desc = "Close terminal buffer (false)" }) + + +-- Alternative file navigation +map("n", "ak", function() + alternative_file.open("next", "--exists") +end, { desc = "Next alternative file" }) +map("n", "aj", function() + alternative_file.open("prev", "--exists") +end, { desc = "Previous alternative file" }) + + +map("t", "", "", { desc = "Escape terminal mode" }) +map("t", "jj", "", { desc = "Escape terminal mode with jj" }) + + +-- From old, might be dup +-- -- Jumps to the next position after the closest closing char +-- map("i", ",e", "/[\\]})\"']:nohlsearcha", { desc = "Jump to next closing char" }) +-- +-- -- Adds arrow +-- map("i", "", "=>", { desc = "Insert arrow" }) +-- +-- -- Rails specific +-- map( +-- "v", +-- "h", +-- ':s/\\:\\([a-zA-Z_]\\+\\)\\s\\+=>/\\=printf("%s:", submatch(1))/g:let @/ = ""', +-- { desc = "Convert hash rocket to symbol" } +-- ) +-- map("n", "qq", ":q", { desc = "Quit" }) +-- +-- -- Reload buffer +-- map("n", "rel", ":e", { desc = "Reload buffer" }) +-- +-- -- Find +-- map("n", "f", "/", { desc = "Find" }) +-- map("n", "*", ":find", { desc = "Find file" }) +-- +-- -- Use Q for formatting the current paragraph (or selection) +-- map("v", "Q", "gq", { desc = "Format selection" }) +-- map("n", "Q", "gqap", { desc = "Format paragraph" }) +-- +-- -- Buffer resizing mappings (shift + arrow key) +-- map("n", "", "+", { desc = "Resize buffer up" }) +-- map("n", "", "-", { desc = "Resize buffer down" }) +-- map("n", "", "<", { desc = "Resize buffer left" }) +-- map("n", "", ">", { desc = "Resize buffer right" }) +-- +-- map("n", "xx", ":!chmod +x %", { desc = "Make file executable" }) +-- +-- map("n", "b", "Telescope current_buffer_fuzzy_find", { desc = "Search in current buffer" }) +-- +-- -- Marks +-- map("n", "mA", "ma", { desc = "Set mark 'a'" }) +-- map("n", "ma", "'a", { desc = "Go to mark 'a'" }) +-- map("n", "m1", "'a", { desc = "Go to mark 'a'" }) +-- +-- map("n", "mB", "mb", { desc = "Set mark 'b'" }) +-- map("n", "mb", "'b", { desc = "Go to mark 'b'" }) +-- map("n", "m2", "'b", { desc = "Go to mark 'b'" }) +-- +-- map("n", "mC", "mc", { desc = "Set mark 'c'" }) +-- map("n", "mc", "'c", { desc = "Go to mark 'c'" }) +-- map("n", "m3", "'c", { desc = "Go to mark 'c'" }) +-- +-- map("n", "mD", "md", { desc = "Set mark 'd'" }) +-- map("n", "md", "'d", { desc = "Go to mark 'd'" }) +-- map("n", "m4", "'d", { desc = "Go to mark 'd'" }) +-- +-- map("n", "mE", "me", { desc = "Set mark 'e'" }) +-- map("n", "me", "'e", { desc = "Go to mark 'e'" }) +-- map("n", "m5", "'e", { desc = "Go to mark 'e'" }) +-- +-- -- Notes +-- map("n", "no", ":vs ~/.tmp/notes.md", { desc = "Open notes" }) diff --git a/lua/user/options.lua b/lua/user/options.lua index a618842..2aff17a 100644 --- a/lua/user/options.lua +++ b/lua/user/options.lua @@ -19,3 +19,8 @@ vim.opt.cursorline = true vim.opt.signcolumn = "yes" vim.opt.updatetime = 300 vim.opt.scrolloff = 8 + + +-- Diagnostic config +-- TODO: Do I still need this? +-- vim.diagnostic.config({ virtual_text = false }) diff --git a/old/lua/config/keymaps.lua b/old/lua/config/keymaps.lua deleted file mode 100644 index c42d958..0000000 --- a/old/lua/config/keymaps.lua +++ /dev/null @@ -1,196 +0,0 @@ --- Keymaps are automatically loaded on the VeryLazy event --- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua --- Add any additional keymaps here - --- TODO: There are mappings that I did not port yet --- For instance: https://github.com/mjacobus/lvim/tree/main/after/ftplugin --- https://github.com/mjacobus/lvim/tree/main/after/plugin --- https://github.com/mjacobus/lvim/tree/main/autoload --- https://github.com/mjacobus/lvim/blob/main/after/plugin/legacy_setup.vim#L179-L212 --- Maybe some here: https://github.com/mjacobus/lvim/blob/main/lua/config/mappings.lua --- And here - -vim.keymap.del("n", "ff") -- conflicts with fword - -local map = LazyVim.safe_keymap_set - --- better up/down -map("i", "jj", "", { desc = "Go to normal mode" }) -map("n", "w", "write", { desc = "Save file" }) - -map("v", "", function() - alternative_file.open("next", "--exists") -end, { desc = "Open next alternative file" }) - -local alternative_file = require("mj.alternate_file") - -map("n", "irc", function() - require("mj.ruby_utils").insert_ruby_class_based_on_file_path() -end, { desc = "Insert ruby class" }) - --- this is not working correctly --- map("v", "irc", function() --- require("mj.ruby_utils").replace_selected_text_with_ruby_class() --- end, { desc = "Replace selected text ruby class" }) - -map("n", "aj", function() - alternative_file.open("prev", "--exists") -end, { desc = "Open previous alternative file" }) - --- Key mappings -map("n", "Q", "q!", { desc = "Quit" }) -map("n", "q", "bdelete", { desc = "Close buffer" }) -map("n", "bdd", "bdelete!", { desc = "Close buffer!" }) -map("n", "bda", "bufdo %bd!", { desc = "Close all buffers!" }) - --- Notes -map("n", "et", ":e ~/.tmp/notes/", { desc = "Edit notes" }) -map("n", "on", ":e ~/.tmp/notes/notes.md", { desc = "Open notes" }) -map("n", "con", ":e ~/.tmp/notes/notes.md", { desc = "Open notes" }) - -map("n", "j", function() - require("mj.utils").close_terminal_buffer(true) -end, { desc = "Close terminal buffer (true)" }) - -map("n", "k", function() - require("mj.utils").close_terminal_buffer(false) -end, { desc = "Close terminal buffer (false)" }) - --- Search mappings -map("n", "f", "/", { desc = "Search alias" }) -map("n", "F", "nohlsearch", { desc = "Remove search highlight" }) - --- Alternative file -map("n", "af", "", { desc = "Alternative file" }) - --- Avoid arrow keys in command mode -map("c", "", "", { desc = "Move left" }) -map("c", "", "", { desc = "Move down" }) -map("c", "", "", { desc = "Move up" }) -map("c", "", "", { desc = "Move right" }) -map("c", "", "", { desc = "Delete" }) - --- Alternative file navigation -map("n", "ak", function() - alternative_file.open("next", "--exists") -end, { desc = "Next alternative file" }) -map("n", "aj", function() - alternative_file.open("prev", "--exists") -end, { desc = "Previous alternative file" }) - --- Diagnostic config -vim.diagnostic.config({ virtual_text = false }) - --- Running tests -map("n", "at", function() - require("mj.test_runner").run_all_tests() -end, { desc = "Run all tests" }) - -map("n", "t", function() - require("mj.test_runner").test_line() -end, { desc = "Run test for current line" }) - -map("n", "t", function() - require("mj.test_runner").test_line() -end, { desc = "Run test for current line" }) - -map("n", "T", function() - require("mj.test_runner").run_test_file() -end, { desc = "Run test file" }) - -map("n", "st", function() - require("mj.test_runner").run_shell_test() -end, { desc = "Run ./shell_test" }) - --- quick fix -map("n", "gn", ":cnext", { desc = "Next quickfix occurrency" }) -map("n", "gp", ":cprev", { desc = "Previous quickfix occurrency" }) - --- rm file -map("n", "rm", ":Delete", { desc = "Delete file" }) - --- Last buffer -map("n", "o", "", { desc = "Last buffer" }) - --- Escape terminal mode with jj -map("t", "", "", { desc = "Escape terminal mode" }) -map("t", "jj", "", { desc = "Escape terminal mode with jj" }) - --- Buffer changing -map("n", "bn", ":bn", { desc = "Next buffer" }) -map("n", "bp", ":bp", { desc = "Previous buffer" }) - --- Find buffer file -map("n", "b", ":b", { desc = "Find buffer file" }) - --- Search -map("n", "*", "*N", { desc = "Search and stay" }) - --- Select all -map("n", "a", "ggVG", { desc = "Select all" }) - --- New tab -map("n", "t", ":tabnew", { desc = "New tab" }) - --- Jumps to the next position after the closest closing char -map("i", ",e", "/[\\]})\"']:nohlsearcha", { desc = "Jump to next closing char" }) - --- Adds arrow -map("i", "", "=>", { desc = "Insert arrow" }) - --- Rails specific -map( - "v", - "h", - ':s/\\:\\([a-zA-Z_]\\+\\)\\s\\+=>/\\=printf("%s:", submatch(1))/g:let @/ = ""', - { desc = "Convert hash rocket to symbol" } -) -map("n", "qq", ":q", { desc = "Quit" }) - --- Reload buffer -map("n", "rel", ":e", { desc = "Reload buffer" }) - --- Find -map("n", "f", "/", { desc = "Find" }) -map("n", "*", ":find", { desc = "Find file" }) - --- Use Q for formatting the current paragraph (or selection) -map("v", "Q", "gq", { desc = "Format selection" }) -map("n", "Q", "gqap", { desc = "Format paragraph" }) - --- Buffer resizing mappings (shift + arrow key) -map("n", "", "+", { desc = "Resize buffer up" }) -map("n", "", "-", { desc = "Resize buffer down" }) -map("n", "", "<", { desc = "Resize buffer left" }) -map("n", "", ">", { desc = "Resize buffer right" }) - -map("n", "xx", ":!chmod +x %", { desc = "Make file executable" }) - -map("n", "b", "Telescope current_buffer_fuzzy_find", { desc = "Search in current buffer" }) - --- Marks -map("n", "mA", "ma", { desc = "Set mark 'a'" }) -map("n", "ma", "'a", { desc = "Go to mark 'a'" }) -map("n", "m1", "'a", { desc = "Go to mark 'a'" }) - -map("n", "mB", "mb", { desc = "Set mark 'b'" }) -map("n", "mb", "'b", { desc = "Go to mark 'b'" }) -map("n", "m2", "'b", { desc = "Go to mark 'b'" }) - -map("n", "mC", "mc", { desc = "Set mark 'c'" }) -map("n", "mc", "'c", { desc = "Go to mark 'c'" }) -map("n", "m3", "'c", { desc = "Go to mark 'c'" }) - -map("n", "mD", "md", { desc = "Set mark 'd'" }) -map("n", "md", "'d", { desc = "Go to mark 'd'" }) -map("n", "m4", "'d", { desc = "Go to mark 'd'" }) - -map("n", "mE", "me", { desc = "Set mark 'e'" }) -map("n", "me", "'e", { desc = "Go to mark 'e'" }) -map("n", "m5", "'e", { desc = "Go to mark 'e'" }) - --- Notes -map("n", "no", ":vs ~/.tmp/notes.md", { desc = "Open notes" }) - --- shell_test -map("n", "1", ":e shell_test", { desc = "Open shell_test" })