Skip to content

Commit

Permalink
feat(nvim): add vim magic keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinyuz committed Mar 17, 2024
1 parent efd6c02 commit ea086a6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions nvim/.config/nvim/lua/my/maps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,29 @@ end, { desc = 'copy current absolute filename to system clipboard' })
vim.keymap.set({ 'n', 'v' }, '<leader>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 })

0 comments on commit ea086a6

Please sign in to comment.