http://vim.wikia.com/wiki/Command_for_searching_expressions_%28paths%29_wich_include_backslashes
but I'm not sure that this is the best way to achieve the desired goal.
Is there a best way?
Thanks
Giacomo
--
##############################################################
giacomo 'giotti' mariani
gpg --keyserver pool.sks-keyservers.net --recv-key 0x99bfa859
O< ASCII ribbon campaign: stop HTML mail
www.asciiribbon.org
##############################################################
that link shows me an empty page ("This page needs content...")
> but I'm not sure that this is the best way to achieve the desired goal.
> Is there a best way?
>
Simply assign your search string directly to the search-register, e.g.
if you have your search string in the Clipboard, use:
:let @/=@+
and press n to jump to the next occurence.
Of course you can also assign it manually:
:let @/='/path/with/many/slashes'
regards,
Christian
Or you can search backwards with "?":
?/path/to/wherever/with/slashes
If you want to change the direction of the search (rather than
using the somewhat awkwardly-inverted n/N commands), you can then
search forwards with no search criteria which will reuse the
previous pattern without the need to escape it.
-tim
*g*, when searching backwards, I always get confused, whether to use
n/N for my desired direction. Is 'n' keeping the direction or searching
forward? And if 'N' reverses the direction and ? also reverses the
direction this reverses twice? That is too confusing for me...
So I try to avoid ?-search and jump to a place from which I can search
forward.
regards,
Christian
while it took me a while to figure it out (and remember it), it
still doesn't feel totally natural to think that "n" means "keep
searching in the same direction as my last search, whatever that
was", so unless I've JUST done a backwards "?" search, I find it
a bit cumbersome and side with you. Though sometimes setting
'nowrapscan' helps me keep them straight because I can then tell
when I hit the top/bottom of the file.
-tim
? n n n n searches repeatedly backwards. Then hit N to search forward,
and n to search backward again.
Best regards,
Tony.
--
"Death is nature's way of saying `Howdy'".
On Mi, 06 Apr 2011, Tony Mechelynck wrote:
> ? n n n n searches repeatedly backwards. Then hit N to search
> forward, and n to search backward again.
I *know* that. Just my fingers...
(When I navigate code and jump around a lot, I tend to forget, in which
direction I originally searched. I usually only know that I want to move
downwards, so I hit 'n' and I hate when Vim moves upwards...)
That's why I try to avoid the ? search.
regards,
Christian
--
Das Leben ist kurz, und es wird im Jenseits keiner nach der Zahl der
B�cher gefragt, die er bew�ltigt hat. Darum ist es unklug und
sch�dlich, mit wertloser Lekt�re Zeit hinzubringen.
-- Hermann Hesse (�ber das Leben)
And the only thing worse than expecting "n" to move downwards
only to have it move upwards is having a file that's so similar
(such as a long tab/CSV file) where you can't readily tell
whether you've gone up or down :)
I confess, while Vim has a profusion of options, that's one I
wouldn't mind seeing...something that toggled between "n means
next in the same search-direction as last time" and "n means
search downward in the file". I suppose I could do something like
:nnoremap n /<cr>
:nnoremap N ?<cr>
if it really bugged me that much.
-tim
On Mi, 06 Apr 2011, Tim Chase wrote:
> On 04/06/2011 12:50 PM, Christian Brabandt wrote:
> >>? n n n n searches repeatedly backwards. Then hit N to
> >>search forward, and n to search backward again.
> >
> >I *know* that. Just my fingers...
> >
> >(When I navigate code and jump around a lot, I tend to forget,
> >in which direction I originally searched. I usually only know
> >that I want to move downwards, so I hit 'n' and I hate when
> >Vim moves upwards...)
>
> And the only thing worse than expecting "n" to move downwards only
> to have it move upwards is having a file that's so similar (such as
> a long tab/CSV file) where you can't readily tell whether you've
> gone up or down :)
Oh yes, I know that...
regards,
Christian
For the record, the actual title has a dot ('.') at the end:
http://vim.wikia.com/wiki/Command_for_searching_expressions_%28paths%29_wich_include_backslashes.
I have put the information discussed here into the comments in
the tip and will clean it up later.
John
Hm, apparently my mailer did not include the period in the link. The
following should work:
http://vim.wikia.com/wiki/Command_for_searching_expressions_%28paths%29_wich_include_backslashes%2E
Also, maybe that wiki page needs a rename or a redirect.
Best regards,
Tony.
--
It is against the law for a monster to enter the corporate limits of
Urbana, Illinois.
That is going straight into my .vimrc. One of those things that annoys
me, but not enough for me to bother doing anything about it. But if
someone's going to hand me a solution on a plate. :-)
(I guess it's similar to the J-is-not-an-operator thing, which I
recently addressed when something pushed me over the line!).
Smiles,
Ben.
Heh, around 2007 I almost got a headache around this ...
* what's wrong with "n" and "N"
After "d//e" (delete to end of match), "n" (from now on) moves to the
_end_ of the next match, which has become the last search pattern (not
wanted!); also I want "n" to always go forward and "N" go backward
* Solution:
:no n //<cr>
:no N ??<cr>
Problem: First item in the search history ("/" + "Ctrl-P") now is "//" and
not the last search string, I have to press Ctrl-P again (annoying,
because "//" is useless)
* Solution:
:no <silent> n //<cr>:call histdel('/',-1)<cr>
:no <silent> N ??<cr>:call histdel('/',-1)<cr>
Problem: The current search string is no longer echoed (but with <silent>
omitted, ":call histdel(..." will be echoed, even worse).
* Solution:
:no <silent> n //<cr>:call histdel('/',-1)<bar>echo '/'.histget('/',-1)<cr>
:no <silent> N ??<cr>:call histdel('/',-1)<bar>echo '/'.histget('/',-1)<cr>
Problem: The message "search hit BOTTOM, continuing at TOP" is overwritten
by the explicit echo.
* Solution:
:no <script> n //<cr><sid>histdel
:no <script> N ??<cr><sid>histdel
:no <silent> <sid>histdel :call histdel('/',-1)<cr>
Problem: Doesn't work for Visual mode. [21-10-2007]
* Solution:
:no <script> n //<cr><sid>histdel
:no <script> N ??<cr><sid>histdel
:nn <silent> <sid>histdel :call histdel('/',-1)<cr>
:vn <silent> <sid>histdel :<c-u>call histdel('/',-1)<cr>gv
Problem: In Visual mode this produces flickering, Command-line turns
Visual mode off when pressing Enter).
* Solution:
:no <script> n //<cr><sid>histdel
:no <script> N ??<cr><sid>histdel
:nn <silent> <sid>histdel :call<sid>histdel(0)<cr>
:vn <silent> <sid>histdel :<c-u>call<sid>histdel(1)<cr>
:func! <sid>histdel(vmode)
: if a:vmode
: normal! gv
: endif
: call histdel('/',-1)
:endfunc
Problem: If cursor is at `> in Visual mode and `< is not on screen, cursor
positioning is like after doing "oo" (flip to `< and back).
* Solution:
I thought
:vn <silent> <sid>histdel :<c-u>call<sid>histdel(1, line("w0"))<cr>
could help restoring the old position, but it fails.
Although the cursor is at `>, line("w0") always refers to `<, why?
(didn't further investigate here)
What I have now in the vimrc:
ono m //e<CR>
xn <script> m //e<SID>SelOff<CR>
cno <expr> <SID>SelOff &sel=="exclusive" ? "+1" : ""
" do the right thing after o_//e and .
no <script> n //<CR><SID>HistDel
no <script> N ??<CR><SID>HistDel
sunm n|sunm N
nn <silent> <SID>HistDel :call<sid>HistDel(0)<CR>
vn <silent> <SID>HistDel :<C-U>call<sid>HistDel(1)<CR>
ino <silent> <SID>HistDel <C-R>=<sid>HistDel(0)<CR>
func! <sid>HistDel(vmode)
if a:vmode
normal! gv
endif
call histdel('/', -1)
return ""
endfunc
--
Andy
Thanks! I'll give it a try!
Ben.
Problem: Folds are not automatically opened any more
Solution: Add a zv command when "search" is in 'foldopen'
no <script> <expr> n "//<CR>".(&fdo=~"search"?"zv":"")."<SID>HistDel"
no <script> <expr> N "??<CR>".(&fdo=~"search"?"zv":"")."<SID>HistDel"
(The rest is unchanged.)
Ben.
He, thanks, that's right.
But I'd use another script mapping to add the zv; for example, at the
moment, one can't do
(Insert mode) Ctrl-O n
ono m //e<CR>
xn <script> m //e<SID>SelOff<CR>
cno <expr> <SID>SelOff &sel=="exclusive" ? "+1" : ""
no <script> n //<CR><SID>zv<SID>HistDel
no <script> N ??<CR><SID>zv<SID>HistDel
sunm n|sunm N
no <expr> <SID>zv &fdo=~"search" ? "zv" : ""
imap <SID>zv <Nop>
nn <silent> <SID>HistDel :call<sid>HistDel(0)<CR>
vn <silent> <SID>HistDel :<C-U>call<sid>HistDel(1)<CR>
ino <silent> <SID>HistDel <C-R>=<sid>HistDel(0)<CR>
func! <sid>HistDel(vmode)
if a:vmode
normal! gv
endif
call histdel('/', -1)
return ""
endfunc
--
Andy
function s:SetSearch(sstr)
let @/=@/
return a:sstr
endfunction
noremap <expr> n <SID>SetSearch('Nn'[v:searchforward])
noremap <expr> N <SID>SetSearch('nN'[v:searchforward])