在Vim中将一对括号更改为方括号的最快方法 [英] Quickest way to change a pair of parenthesis to brackets in vim
问题描述
我是vim的新手,正在发现许多有趣的东西,而这些东西可以使用此功能强大的编辑器来进行.
I am new to vim and in the process of discovering tons of interesting things that one can using this powerful editor.
我需要经常做的一件事是将文本中的一对括号更改为方括号(例如,将( (a+b+c) )
更改为[ (a+b+c) ]
),反之亦然.现在,我通过手动将两个字符(
和)
更改为[
和]
来做到这一点.
One particular thing that I need to do very frequently is to change a pair of parenthesis in the text to square-brackets (for example to change ( (a+b+c) )
to [ (a+b+c) ]
) or vice-verso. I now do this by manually changing the two characters (
and )
to [
and ]
.
但是,当括号之间有很多文本时,可能很难找到一对开括号,特别是因为在将第一个(
更改为[
之后,%
命令将不再能够找到相应的)
.
However, when there is a lot of text in between the parenthesis, it could be difficult to locate the pair of opening and closing parenthesis especially because after changing the first (
to [
then the %
command will no longer be able to find the corresponding )
.
我想知道是否有更好,更快的方式进行此类更改?
I was wondering if there is a better and quicker way to make such changes?
推荐答案
我只需这样做:%r]^or[
.
这里是一个解释:
-
f(
-将光标放在要更改的第一个括号上(如果尚不存在的话). -
%
-跳转到匹配的括号. -
r]
-用括号替换括号. -
CTRL-O
-跳回到第一个括号. -
r[
-用括号替换括号.
f(
-- put cursor on first parenthesis you want to change (if it's not already there).%
-- jump to the matching parenthesis.r]
-- replace the parenthesis with a bracket.CTRL-O
-- jump back to to first parenthesis.r[
-- replace the parenthesis with a bracket.
这篇关于在Vim中将一对括号更改为方括号的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!