The Computer Oracle

How do I go to the first search result in a file?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3 Looping

--

Chapters
00:00 How Do I Go To The First Search Result In A File?
00:24 Answer 1 Score 6
00:34 Accepted Answer Score 33
01:04 Answer 3 Score 12
01:18 Answer 4 Score 4
01:27 Thank you

--

Full question
https://superuser.com/questions/677940/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#vim

#avk47



ACCEPTED ANSWER

Score 33


ggn will bring you to the first instance of your search in the file -- the gg brings you the beginning of the file and the n goes to the next match of your pattern.

You can also use gg2n to go to the second instance in the file, or gg42n to go to the forty-second instance. You can similarly use G$N to go to the final match (G brings you to the final line, $ brings you to the end of that line, and N searches backwards), or G$2N to go to the penultimate one.




ANSWER 2

Score 12


Obscure Ex commands for the win:

:ij[ump] foo  "jumps to first foo that is not in a comment
:ij[ump]! foo "jumps to first foo, comment or not

See also :il[ist].




ANSWER 3

Score 6


Use the gg command to navigate to the beginning of the file.

gg

/foo



ANSWER 4

Score 4


The gD command will search from the top of the file for the word under the cursor.

The related gd command will search from the top of the current c-like function.