[vox-tech] vim question: restoring search term after a mapping

Matt Roper matt at mattrope.com
Mon Jul 19 16:10:50 PDT 2004


On Mon, Jul 19, 2004 at 03:36:48PM -0700, Henry House wrote:
> 
> I have some mappings in my ~/.vimrc:
> 
> 	nmap =0 :.s/^\(.\+\)$/\\chapter{\1}/<CR>:noh<CR>
> 	nmap =1 :.s/^\(.\+\)$/\\section{\1}/<CR>:noh<CR>
> 	nmap =2 :.s/^\(.\+\)$/\\subsection{\1}/<CR>:noh<CR>
> 	nmap =3 :.s/^\(.\+\)$/\\subsubsection{\1}/<CR>:noh<CR>
> 
> which work great, but with one annoying aspect: they replace the current
> search term. It is a bother to have to re-enter my search term (i.e., what I
> last entered into the / command) after every use of my handy mappings. Does
> anyone know a way to grab the current contents of the search-term register,
> save it somewhere, then restore it?  Note that I do not actually want to run
> a search again, just get back the saved search term so that the n command
> will work as expected the next time that I run it after using one of my
> handy mappings.

I think @/ might be what you're looking for.  See ":help last-pattern"
for details.


Matt

-- 

*************************************************
* Matt Roper <matt at mattrope.com>                *
* http://www.mattrope.com                       *
* PGP Key: http://www.mattrope.com/mattrope.asc *
*************************************************


More information about the vox-tech mailing list