@@ -102,3 +102,29 @@ end, { desc = 'copy current absolute filename to system clipboard' })
102102vim .keymap .set ({ ' n' , ' v' }, ' <leader>cf' , function ()
103103 require (' my.format' ).format ()
104104end )
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