Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
133 views
in Technique[技术] by (71.8m points)

Searching from end of file using VIM

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.

question from:https://stackoverflow.com/questions/12867573/searching-from-end-of-file-using-vim

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

My suggestion is to use a range combined with searching backwards via ?.

:1?XXXX

Overview:

  • 1?XXXX is the range.
  • The 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...