Skip to content

Commit ea086a6

Browse files
committed
feat(nvim): add vim magic keymap
1 parent efd6c02 commit ea086a6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

nvim/.config/nvim/lua/my/maps.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,29 @@ end, { desc = 'copy current absolute filename to system clipboard' })
102102
vim.keymap.set({ 'n', 'v' }, '<leader>cf', function()
103103
require('my.format').format()
104104
end)
105+
106+
-- Automatically add vim magic to search and substitue
107+
vim.keymap.set({ 'n', 'v' }, '/', '/\\v', { noremap = true })
108+
vim.keymap.set({ 'n', 'v' }, '?', '?\\v', { noremap = true })
109+
110+
vim.keymap.set('c', '/', function()
111+
-- Get the previous command-line text
112+
local line = vim.fn.getcmdline()
113+
-- Check if the previous text is "%s"
114+
if line == '%s' or line == "'<,'>s" then
115+
return '/\\v'
116+
end
117+
118+
return '/'
119+
end, { noremap = true, expr = true })
120+
121+
vim.keymap.set('c', '?', function()
122+
-- Get the previous command-line text
123+
local line = vim.fn.getcmdline()
124+
-- Check if the previous text is "%s"
125+
if line == '%s' or line == "'<,'>s" then
126+
return '?\\v'
127+
end
128+
129+
return '?'
130+
end, { noremap = true, expr = true })

0 commit comments

Comments
 (0)