Tip #340: Visual Select And Search
tip karma |
Rating 13/4, Viewed by 730
|
created: |
|
October 10, 2002 18:59 |
|
complexity: |
|
intermediate |
author: |
|
Chris Butler ([email protected]) |
|
as of Vim: |
|
6.0 |
The following visual select and search map is a combination of information
from Benji's vimrc file (vmap S y/<C-R>=escape(@",'/')<CR>) and a tip that
mentions the "\n" to "\\\\n" substitution.
It works for special characters and multiple lines.
vmap \s y/\V<C-R>=substitute(escape(@",'/'),"\n","\\\\n","g")<CR>/<CR>
Quick explanation:
vmap visual map
\s your choice
y yank selected text
/ search delimiter
\V no magic, just text
<C-R>= expression
substitute substitute "\n" for "\\\\n"
escape escape '/' (delimiter) and '' in yanked text (@")
<CR> end expression
/<CR> search
Warning: Folding will not match if the foldexpr expression is using
getline() to match against a search pattern that spans multiple lines.
Enjoy.
<<"tabbed windows" |
switch color schemes >>
Additional Notes
|