VIM直接查询选中文本

在使用Vim的时候会经常用到查询功能,Vim默认的查询往往需要你输入要查询的字符串,要查询的字符串明明已经在文件里面了还要在输入一遍 真是麻烦啊。我就想Vim能不能像某些文本编辑器一样,选中一些文本,查询的时候自动把文本拷贝到查询框。Goolge了一下,果真发现有一个这样的vim tip:

 

http://vim.wikia.com/wiki/VimTip171

 

他的主要功能有:

 

  • Press * to search forwards for selected text, or # to search backwards. - 用*向前查询选中词,用#向后查询
  • As normal, press n for next search, or N for previous. As normal, press n for next search, or N for previous. - n/N照常
  • Handles multiline selection and search. Handles multiline selection and search. (下面的不太用到,就不翻译了:))
  • Whitespace in the selection matches any whitespace when searching (searching for "hello world" will also find "hello" at the end of a line, with "world" at the start of the next line). Whitespace in the selection matches any whitespace when searching (searching for "hello world" will also find "hello" at the end of a line, with "world" at the start of the next line).
  • Each search is placed in the search history allowing you to easily repeat previous searches. Each search is placed in the search history allowing you to easily repeat previous searches.
  • No registers are changed. No registers are changed.
  • A global variable (g: VeryLiteral) controls whether selected whitespace matches any whitespace (by default, VeryLiteral is off, so any whitespace is found).
  • Type /vl to toggle VeryLiteral to turn whitespace matching off/on (assuming the default backslash leader key). Type / vl to toggle VeryLiteral to turn whitespace matching off / on (assuming the default backslash leader key).
  • When VeryLiteral is off, any selected leading or trailing whitespace will not match newlines, which is more convenient, and avoids false search hits. When VeryLiteral is off, any selected leading or trailing whitespace will not match newlines, which is more convenient, and avoids false search hits.

 

把下面的代码保存为vsearch.vim 放到~/.vim/plugins目录下,就可以使用了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值