sponsor Vim development Vim logo Vim Book Ad

basic Tip #655: search with one key

 tip karma   Rating -3/7, Viewed by 1158 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   February 16, 2004 13:06      complexity:   basic
author:   vim_user      as of Vim:   5.7

* is 2 keys (shift and press 8)
I found it simpler to map these to a single key.

put these mappings in your _vimrc file

:nmap  <F8> :execute ":normal #"<CR>

:nmap  <F9> :execute ":normal *"<CR>

Now you can search for the word under the cursor in normal mode with the F8 key backwards and the F9 key forwards.

Can this be done in insert mode?

 rate this tip  Life Changing Helpful Unfulfilling 

<< special characters in VIM substitution | Recursive mappings - (2 examples to learn from) >>

Additional Notes

sandor.kopanyi@essnet.se, February 16, 2004 23:41
In insert mode just escape to normal mode, do the same thing, then go back to insert mode with "a":

:imap  <F8> <Esc> :execute ":normal #"<CR> a

:nmap  <F9> <Esc> :execute ":normal *"<CR> a
Peter Palm, February 17, 2004 4:55
To execute just one command in normal mode (from insert mode), use <C-O>.

The mapping above could be written as:
:imap  <F8> <C-O>#
:imap  <F9> <C-O>*
anon, February 17, 2004 10:06
see also vimtip #154
Anonymous, February 19, 2004 8:17
Those nmaps are more than required, try:
:nmap  <F8> #
:nmap  <F9> *
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo