sponsor Vim development Vim logo Vim Book Ad

basic Tip #1079: map <F3> to find exactly one word

 tip karma   Rating -13/19, Viewed by 1951 

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

created:   December 14, 2005 18:35      complexity:   basic
author:   Sérgio Luiz Araújo Silva      as of Vim:   5.7

map <F3> /\<\><left><left><c-r><c-w>
imap <F3> <esc>/\<\><left><left><c-r><c-w>

<esc>   exit insert mode
/     begin find
\<   begin word
\>   end word
<left> "two times" move cursor to \<"position"\>
<c-r><c-w> command get word under cursor to command line or find

 rate this tip  Life Changing Helpful Unfulfilling 

<< Best way to close (delete) buffer without closing its window | Map caps-lock to ESC >>

Additional Notes

Anonymous, December 14, 2005 18:39
add confirm command <cr>

imap <F3> <esc>/\<\><left><left><c-r><c-w><cr>

<esc>   exit insert mode
/     begin find
\<   begin word
\>   end word
<left> "two times" move cursor to \<"position"\>
<c-r><c-w> command get word under cursor to command line or find
<cr>  confirm command
Anonymous, December 14, 2005 21:04
isn't this just what '*' does?
pagaltzis@gmx.de, December 14, 2005 22:32
Errm, see vimtip #1 – use * to find the word under the cursor.
Gerald Lai, December 14, 2005 22:39
See vimtip#1038. Suggestion by "shankar.r@freescale.com" is good.

"visual search
vmap *           y/\V<C-r>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
vmap <kMultiply> y/\V<C-r>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
vmap #           y?\V<C-r>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
http://byculla.blogspot.com, December 17, 2005 8:04

" Search for visual-selection literally ignoring spacing across lines. *****

" Like google phrase search - select set of words and search
" selected phrase disregarding spaces/newlines 'v <move cursor> /<CR>'

:vmap <silent> //  y/<C-R>=substitute(escape(substitute(@","\\n"," ","g"), "\\/.*$^~[]"), "[ \\t\\n\\r]\\+","\\\\_s\\\\+","g")<CR><CR>  
fei.fei@intel.com, December 18, 2005 18:22
Use "#" to match previous word and "*" to match next word ...
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