更改VIM中接下来的N个字符
假设我有以下行:
|add_test() (| == cursor position)
并且想要将“add”替换为“del”。
del|_test()
我可以按 X 三次,然后按 i 插入并输入 del。 我想要的是像 3c 或 3r 这样的东西来覆盖 3 个字符。 这两个都没有达到我想要的效果,3c 用相同的内容覆盖 3 个字符 角色,3r 还做了其他几件事。
有没有一种简单的方法可以做到这一点,而无需手动 Xing 和插入文本?
Say I have the following line:
|add_test() (| == cursor position)
And want to replace the 'add' with a 'del'.
del|_test()
I can either press X three times and then press i to insert and type del.
What I want is something like 3c or 3r to overwrite just 3 characters.
Both of these don't do what I want, 3c overwrites 3 characters with the same
character, 3r does several other things.
Is there an easy way to do this without manually Xing and inserting the text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
3s
,“替换3个字符”与c3l
相同。3cl
和c3l
应该是相同的,我不知道为什么你会看到相同的字符重复。我也喜欢使用t
,例如另一张海报提到的ct_
,这样我就不必计算字符数,只需输入“del”即可。我也为“替换几个字符”而苦苦挣扎了几天; 'r' 非常适合单个字符,
R
非常适合匹配长度的字符串,但我想要像OP所要求的东西。于是,我输入:help x
看了一会儿,发现s
和S
的描述只有几页纸从x
向下。换句话说,
:help
是你的朋友。阅读和学习。3s
, "substitute 3 characters" is the same asc3l
.3cl
andc3l
should be the same, I don't know why you'd see the same character repeated. I'm also a fan of usingt
, e.g.ct_
as another poster mentioned, then I don't have to count characters and can just type "del".I struggled with the "replace a couple of characters" for a few days too; 'r' was great for single characters,
R
was great for a string of matching length, but I wanted something like the OP is asking for. So, I typed:help x
and read for a while, it turns out that the description ofs
andS
are just a couple of pages down fromx
.In other words,
:help
is your friend. Read and learn.使用c{motion}命令:
该单词由iskeyword变量确定。使用 :set iskeyword? 检查并删除任何“_”,例如 :set iskeyword=@,48-57,192-255。
顺便说一句,如果您想要更多信息,请参阅:help c和:helpmotion。
Use c{motion} command:
The word is determined by iskeyword variable. Check it with :set iskeyword? and remove any '_', like that :set iskeyword=@,48-57,192-255.
By the way see :help c and :help motion if you want more.
我认为
3cl
就是你想要的。它向右改变 3 个字符。我会输入ct_del
,但这不是您要求的I think
3cl
is what you want. It changes 3 characters to the right. I'd typect_del<esc>
, but that's not what you askedc3
('c', '3', space),然后键入要插入的字符。 (或者您可以使用右箭头或l
而不是空格。)或者,正如 @Mike 刚刚在评论中所说,如果字符数恰好满足,则
R
效果很好。匹配您要删除的字符数。或者
ct_
从光标更改到下一个_
字符。或者,正如 @bloody 在评论中建议的那样,
3s
。c3
('c', '3', space), then type the characters you want to insert. (Or you can use right-arrow orl
rather than space.)Or, as @Mike just said in a comment,
R
works nicely if the number of characters happens to match the number of characters you're deleting.Or
ct_
to change from the cursor to the next_
character.Or, as @bloody suggests in a comment,
3s
.如果作品长度相同,您可以使用 R 命令将您之前输入的内容替换为您输入的内容。
If the works have the same length you can use the
R
command which replaces what you had previously with what you type.给出的其他答案使用数字。当文本较长时,就更容易不必计数。例如,我经常在 markdown 文件中制作标题,例如:
一些我不想计算的超级长标题
用
yy
双行pp
一些超级长的标题,我不想计数
一些我不想数的超长标题
使用
V
突出显示整行然后使用
r{char}
或在本例中r=
来获取:一些我不想计算的超级长标题
=================================================== ===========
(我在上面添加了一个空格来旅行堆栈溢出的降价格式)
The other answers given use numbers. When the text is longer it's easier to not have to count. For example I often make headlines in markdown files like:
Some super duper long title that I don't want to have to count
double the line with
yy
pp
Some super duper long title that I don't want to have to count
Some super duper long title that I don't want to have to count
Highlighth the whole line with
V
then use
r{char}
or in this caser=
to get:Some super duper long title that I don't want to have to count
==============================================================
(I added a space above to trip stack overflow's markdown formatting)