No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
This tricks explain how to search a path of the form <tt>/path/to/</tt> without leading slash. They are based on magic, on the function escape and on various contributions from the mailing-list. |
This tricks explain how to search a path of the form <tt>/path/to/</tt> without leading slash. They are based on magic, on the function escape and on various contributions from the mailing-list. |
||
− | + | =Super Serach= |
|
− | =Ss command= |
+ | ==Ss command== |
Inserting in your vimrc the following line: |
Inserting in your vimrc the following line: |
||
<pre> |
<pre> |
||
Line 22: | Line 22: | ||
gives you the new command <tt>Ss</tt> which search for expressions in which backslashes are automatically escaped: / -> \/ |
gives you the new command <tt>Ss</tt> which search for expressions in which backslashes are automatically escaped: / -> \/ |
||
− | =SS command= |
+ | ==SS command== |
Inserting in your vimrc the following line: |
Inserting in your vimrc the following line: |
||
<pre> |
<pre> |
||
Line 31: | Line 31: | ||
− | + | =Following is a paraphrase of some comments on this topic from the vim_use mailing list:= |
|
− | =Clipboard direct editing= |
+ | ==Clipboard direct editing== |
If you have copied a path like <tt>/abc/def/xyz</tt> into the clipboard, you can search for that text in Vim by assigning it to the search register with command {{tt|1=:let @/=@+}} and then press <tt>n</tt> to search for the next occurrence. |
If you have copied a path like <tt>/abc/def/xyz</tt> into the clipboard, you can search for that text in Vim by assigning it to the search register with command {{tt|1=:let @/=@+}} and then press <tt>n</tt> to search for the next occurrence. |
||
You can also assign a path-with-slashes manually: {{tt|1=:let @/ = '/abc/def/xyz'}} |
You can also assign a path-with-slashes manually: {{tt|1=:let @/ = '/abc/def/xyz'}} |
||
− | =Reverse searching= |
+ | ==Reverse searching== |
An alternative is to search backwards with "<tt>?</tt>" which treats slashes in the pattern as normal characters. After searching backwards, you can press <tt>n</tt> to continue searching in the same direction (backwards), or <tt>N</tt> to search in the reverse direction (forwards). Or, you can search forwards with <tt>/</tt> and no pattern, which will use the previous pattern: |
An alternative is to search backwards with "<tt>?</tt>" which treats slashes in the pattern as normal characters. After searching backwards, you can press <tt>n</tt> to continue searching in the same direction (backwards), or <tt>N</tt> to search in the reverse direction (forwards). Or, you can search forwards with <tt>/</tt> and no pattern, which will use the previous pattern: |
||
<pre> |
<pre> |
Revision as of 09:11, 7 April 2011
Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).
This tricks explain how to search a path of the form /path/to/ without leading slash. They are based on magic, on the function escape and on various contributions from the mailing-list.
Super Serach
Ss command
Inserting in your vimrc the following line:
command! -nargs=1 Ss let @/ = escape('<args>', '/')
gives you the new command Ss which search for expressions in which backslashes are automatically escaped: / -> \/
SS command
Inserting in your vimrc the following line:
command! -nargs=1 SS let @/ = '\V'.escape("<args>",'/')
gives you the new command SS which search for expressions in which all magic characters and the backslashes are automatically escaped: / -> \/; $ -> \$ ...
Following is a paraphrase of some comments on this topic from the vim_use mailing list:
Clipboard direct editing
If you have copied a path like /abc/def/xyz into the clipboard, you can search for that text in Vim by assigning it to the search register with command :let @/=@+ and then press n to search for the next occurrence.
You can also assign a path-with-slashes manually: :let @/ = '/abc/def/xyz'
Reverse searching
An alternative is to search backwards with "?" which treats slashes in the pattern as normal characters. After searching backwards, you can press n to continue searching in the same direction (backwards), or N to search in the reverse direction (forwards). Or, you can search forwards with / and no pattern, which will use the previous pattern:
?/abc/def/xyz /
Now, pressing n will search forwards for the next occurrence, and N will search backwards.
References
Comments
We will fix the title later when considering the tip at new tips: the "backslash" in the title is not correct. Of course a slash is / and a backslash is \ and escape('<args>', '/') is escaping slashes not backslashes.
We can use the above in some suitable tip. Thanks vim_use! JohnBeckett 23:24, April 6, 2011 (UTC)