/在或之间是否有捕捉文本的动作\?我知道有其他符号的动议——
ci"- 在里面捕获“文本”"text"
vi(int var-内部视觉捕捉foo(int var)
di[- 删除单词[word]到[]
我能找到的唯一解决方法是使用Vim Surround,并使用它将环境更改\为"( cs\"),然后从那里开始工作。但是,不仅繁琐,而且插件只支持反斜杠,不支持正斜杠。
/在或之间是否有捕捉文本的动作\?我知道有其他符号的动议——
ci"- 在里面捕获“文本”"text"
vi(int var-内部视觉捕捉foo(int var)
di[- 删除单词[word]到[]
我能找到的唯一解决方法是使用Vim Surround,并使用它将环境更改\为"( cs\"),然后从那里开始工作。但是,不仅繁琐,而且插件只支持反斜杠,不支持正斜杠。
你可以很容易地为此编写自己的文本对象。
onoremap <silent> i/ :<C-U>normal! T/vt/<CR> " inside /
onoremap <silent> a/ :<C-U>normal! F/vf/<CR> " around /
让它在视觉模式下工作:
xnoremap <silent> i/ :<C-U>normal! T/vt/<CR> " inside /
xnoremap <silent> a/ :<C-U>normal! F/vf/<CR> " around /
同样,您也可以为\
编辑:添加信息评论。
这是使用映射的一种方法:
nnoremap H mal??e+1<Enter>mb//<Enter>y`b`a
此映射将在最后一次搜索模式的两次出现之间拉取所有内容。
将其放在您的.vimrc文件中以使其永久化。
您的问题的用法:
/\/ 注意反斜杠转义字符)H/上一个和下一个之间的所有/内容都会被猛拉。
解释:
nnoremap H mal??e+1<Enter>mb//<Enter>y`b`a
- nnoremap H map H in normal mode, ignoring other mappings
- ma place a mark (named a) at the current cursor location
- l move the cursor one char to the right
- ??e+1<Enter> move to 1 character after END of prev occurrence of last search pattern
- mb place a mark (named b) at the current cursor location
- //<Enter> go to the beginning of the next occurrence of the last search pattern
- y`b yank to the location of the mark named x (note: ` = "back tick")
- `a go to the mark named `a`
示例输入:
This is a *funky* string
*Hfunky这个词将在 yank 缓冲区中。
示例输入:
<br>
Capture all this text.
<br>
<br>H正常模式<br><br>示例输入:
<p>
Capture this paragraph.
</p>
<.\?p>(或 <\/\{,1}p> 更正确)<p>更好的方法可能是使用寄存器来记住分隔符,因此您可以快速和/或重复使用此映射。换句话说,您可以将/or存储在寄存器中\,<\?p>并使用它来快速捕获存储的分隔符之间的文本。
最近提出的 Vim 补丁为任意匹配对添加了一个文本对象:
https://groups.google.com/d/topic/vim_dev/pZxLAAXxk0M/discussion
没有内置的文本对象slash。但是有插件支持自定义文本对象,例如:
目标