-2

When using vim, I often use the command /foo to jump to some variable foo in a file to look at it. I then remember the line number, press escape and then do :lno to jump to the line number. Is there an easy way to escape search so that my cursor is located at foo (without remembering the line number)?

This question is similar but not write right, as there may be multiple instances of foo in my file. Jump to function definition in vim

Bernie2436
  • 131
  • 6
  • Do you have `:set hls` on? After executing a search, you can use `n` and `p` to navigate through hits? Or you could use `*` and `#` for forward and backward search of the current word under cursor. – Ronny Brendel Jan 30 '18 at 23:35
  • 4
    hit enter instead of escape? – Kevin Jan 30 '18 at 23:37

2 Answers2

0

You need marks. Mark your current cursor position with a command like ma (where a is the name of the mark) and return to it with the command `a or 'a. List marks with the command:

:marks
phd
  • 57,284
  • 10
  • 68
  • 103
0

Why do you press <Esc> to begin with?

Just press <CR> to put the cursor on foo:

/{pattern}[/]<CR>    Search forward for the [count]'th occurrence of
                     {pattern} |exclusive|.
romainl
  • 158,436
  • 18
  • 236
  • 264