How do I search from the end of file using VIM? I want to search for the last occurrence of XXXX in the open file.
Move cursor to end of file in vim In short press the Esc key and then press Shift + G to move cursor to end of file in vi or vim text editor under Linux and Unix-like systems.
View Recent Files Using Windows Search If you want to see all the recent files on your system, Windows Search is the answer. Start by opening File Explorer to the top level folder you want to search. For example, selecting your Documents folder searches everything in that folder and all the subfolders it contains.
Use the up arrow key to go backwards line by line or ctl+b to go page by page. This not only goes to the end of the file, it waits for additional output at the end, like tail -f . If this isn't what you want, you should use +G instead.
Type G$?XXXX
G
to go to the end of the file$
to go to the end of the line?
to search backwardsXXXX
being what you want to search forYou could also do gg?XXXX
which goes to the start of the file, then searches backwards, wrapping around to the end of the file. However for large files it can be slow to seek to the start of the file and then immediately to the end of the file.
My suggestion is to use a range combined with searching backwards via ?
.
:1?XXXX
Overview:
1?XXXX
is the range. 1
means first line of the file.?XXXX
means search backwards from the first line (wrapping around) until you find the pattern XXXX
As ZyX mentioned this relies on wrapscan
to be set, which it is by default. See :h 'wrapscan'
for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With