ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Searching from end of file using VIM

2022-06-17 12:33:54  阅读:150  来源: 互联网

标签:end share Searching XXXX file sheet using data se


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

 

Searching from end of file using VIM

Ask Question Asked 9 years, 8 months ago Modified 3 years, 11 months ago Viewed 64k times   43

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.

Share Improve this question   edited Jun 7, 2013 at 11:49 user avatar Mat 196k4040 gold badges382382 silver badges396396 bronze badges asked Oct 12, 2012 at 21:48 user avatar Ransom Briggs 2,99533 gold badges3131 silver badges4646 bronze badges Add a comment

5 Answers

57

Type G$?XXXX

  • G to go to the end of the file
  • $ to go to the end of the line
  • ? to search backwards
  • XXXX being what you want to search for

You 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.

Share Improve this answer   edited Oct 28, 2013 at 21:06     answered Oct 12, 2012 at 21:51 user avatar David Brown 13k44 gold badges3838 silver badges5454 bronze badges
40  

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.

标签:end,share,Searching,XXXX,file,sheet,using,data,se
来源: https://www.cnblogs.com/kungfupanda/p/16385332.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有