有没有一种方法可以捕获在/
或\
之间的文本?我知道还有其他符号的方法 ---
ci"
- 捕获"text"
中的'text'
vi(
- 在foo(int var)
内部捕获int var
di[
- 删除[word]
单词并保留[]
我唯一能找到的解决方法是使用Vim Surround插件,并将其用于将周围的\
更改为"
(cs\"
),然后从那里开始工作。但是,不仅这种方法很繁琐,而且该插件只支持反斜杠,而不支持正斜杠。
有没有一种方法可以捕获在/
或\
之间的文本?我知道还有其他符号的方法 ---
ci"
- 捕获"text"
中的'text'
vi(
- 在foo(int var)
内部捕获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 /
\
做同样的操作。xnoremap <silent> a/ :<C-U>normal! F/vf/h<CR>/\/[gim]*/e<CR>
目前看起来运行良好! - Andrewxnoremap <silent> a/ :<C-U>normal! F/vf/h<CR>/\/[gimy]*/e<CR>:<C-U>noh<CR>gv
- Andrew这是一种使用映射的方法:
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
*
H
单词funky将被复制到缓冲区。
示例输入:
<br>
Capture all this text.
<br>
<br>
<br>
之间(或第二个<br>
上)按下H
示例输入:
<p>
Capture this paragraph.
</p>
<.\?p>
(或<\/\{,1}p>
更加准确)<p>
标签时)一个更好的方法是使用寄存器来记住分隔符,这样你就可以快速和/或重复地使用这个映射。换句话说,你可以将/
或\
或<\?p>
存储在寄存器中,并使用它来快速捕获存储分隔符之间的文本。
目前没有内置支持 slash
的文本对象。不过有些插件支持自定义文本对象,例如:targets。