Tip #777: More words searching
| tip karma
Rating 57/33, Viewed by 1657
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
||August 27, 2004 3:22
||as of Vim:
Searching a word is nice thing. As you could find in Vim tips, you can search it very fast with ' * ' or ' # ', without
typing word in command window. But what about a searching words or lines? Of course, you type ' / ', and type words
or line like '/a few words', or '/some example line with few words'. Too much typing.
So we can do this much faster. For example, you yank whole line with ' yy ' or ' y$ ', type ' / ' and press <C-R>"
(Control-R and type "). You will see that line pasted. You can even go in visual mode (' v '), select text with move keys, type ' y '
and past it (<C-R>") again; (or you can select text with mouse if you don't like move keys). This is not only for lines, you can select word
or select as many words as you wish.
Here is little bit of explanation for <C-R>. When you type ' / ' (go in search mode), and after that type <C-R>, you will see
' " ' character. Here Vim ask you to type register number or character from whom will paste content. You can type ' " '(temporary
register), 0-9, a-z, etc. even special registers like ' / '(previous search), ' % '(file name), or more better ' . '(register that contain last inserted word). If you want to see all registers and their content, type ' :display ', and paste what you like.
Note, here i placed quotes in ' character, and " character means that you'll need to type it.
Happy searching !
<< Deadkeys / Accented Characters and Mutt integration |
Speed up Pythoner coding >>
August 30, 2004 19:14
|No need for control chars, visually select phrase with
then press // to search, use this mapping:
:vmap // y/<C-R>"<CR>
September 1, 2004 6:17
|There's another version of the above
:vmap <silent> // y/<C-R>=escape(@", '\\/.*$^~')<CR><CR>
This allows the text to search for (ie text visualised) to contain potentially magic characters
from vimtip #305
BTW the idea of using // as the map is really cool thanx!!!
September 1, 2004 17:05
|This tip is awesome, shows what collaboration can do,
which a coporation can never do!
September 1, 2004 22:13
|I have been using the TAB key for more flexible uses...
vmap <C-I> y:/<C-R>"/
" visual HIGHLIGHTED text placed on the COMMAND LINE.
" Input <CR> to perform a search-,
" otherwise EDIT the COMMAND-LINE containing the yanked text.
March 22, 2006 14:00
|Here is my interpretation of this one:
"send all your yanks to the clippboard automatically
"serach for the current visual selection
vnoremap <Leader>/ y/\V<C-R>=escape(@","/\\")<CR><CR>
"serach for the contents of the clippboard
nnoremap <Leader>/ /\V<C-R>*<CR>
Use of "\V" means that in the pattern after it only the backslash has a
special meaning. "very nomagic" :help \V
I usually like to see what the map is doing and so I don't like silent.
I also like using leader in front of my maps. It is sort of like having a
user-defined mode although // in visual mode is an easy one to use
and remeber. :help leader I use comma as my mapleader:
let mapleader = ","
I use these in Linux with ver 6.4