tags:

views:

86

answers:

3

I'm using VIM 7.1

When I search a string in file, the cursor is moved to the beginning of the string found in the text.

Can the cursor be moved at the end instead of the start of the string ?

String where I'm looking for the search

I want cursor at the g of king when I look for king

  • I tried to go to previous result :N

  • I tried to search with ?

+10  A: 

Use /king/e. The e means put the cursor at the end of the match. :help search-offset for more info.

Geoff Reedy
See `:help search-offset` for more information.
jamessan
Great! Thank you.
Luc M
A: 

Yes; use zero-look-behind

/\(king\)\@<=\ 

(Note: there's a space at the end of that line)

Basically, you're looking for the space that follows 'king', and that will jump to it.

BryanH
Wow! +1 But it's easier to remember the `/e` (end)
Luc M
This is not working in my tests. Can you elaborate on the syntax after the close parenthesis?
Alison R.
Basically, A\@<=B means "Find 'B' if and only if it follows 'A'". You can do negative, too: A\@<=!B means "Find 'B' if and only if it *does not* follow 'A'". More: http://www.adp-gmbh.ch/vim/searching.html
BryanH
A: 
nnoremap ,n //e<CR>:let @/=@/<CR>
Nikolay Frantsev