From ea086a6e2f50fe2ebd2caec7440d6ce522cbcf86 Mon Sep 17 00:00:00 2001 From: Eugene Oliveros Date: Sun, 17 Mar 2024 15:30:55 +0800 Subject: [PATCH] feat(nvim): add vim magic keymap --- nvim/.config/nvim/lua/my/maps.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/nvim/.config/nvim/lua/my/maps.lua b/nvim/.config/nvim/lua/my/maps.lua index 0ada2ab2..dfa332ec 100644 --- a/nvim/.config/nvim/lua/my/maps.lua +++ b/nvim/.config/nvim/lua/my/maps.lua @@ -102,3 +102,29 @@ end, { desc = 'copy current absolute filename to system clipboard' }) vim.keymap.set({ 'n', 'v' }, 'cf', function() require('my.format').format() end) + +-- Automatically add vim magic to search and substitue +vim.keymap.set({ 'n', 'v' }, '/', '/\\v', { noremap = true }) +vim.keymap.set({ 'n', 'v' }, '?', '?\\v', { noremap = true }) + +vim.keymap.set('c', '/', function() + -- Get the previous command-line text + local line = vim.fn.getcmdline() + -- Check if the previous text is "%s" + if line == '%s' or line == "'<,'>s" then + return '/\\v' + end + + return '/' +end, { noremap = true, expr = true }) + +vim.keymap.set('c', '?', function() + -- Get the previous command-line text + local line = vim.fn.getcmdline() + -- Check if the previous text is "%s" + if line == '%s' or line == "'<,'>s" then + return '?\\v' + end + + return '?' +end, { noremap = true, expr = true })