更改VIM中接下来的N个字符

发布于 2024-12-02 04:02:11 字数 310 浏览 2 评论 0原文

假设我有以下行:

|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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

帅气尐潴 2024-12-09 04:02:12

3s,“替换3个字符”与c3l相同。 3clc3l 应该是相同的,我不知道为什么你会看到相同的字符重复。我也喜欢使用 t,例如另一张海报提到的 ct_,这样我就不必计算字符数,只需输入“del”即可。

我也为“替换几个字符”而苦苦挣扎了几天; 'r' 非常适合单个字符, R 非常适合匹配长度的字符串,但我想要像OP所要求的东西。于是,我输入 :help x 看了一会儿,发现 sS 的描述只有几页纸从x向下。

换句话说,:help 是你的朋友。阅读和学习。

3s, "substitute 3 characters" is the same as c3l. 3cl and c3l should be the same, I don't know why you'd see the same character repeated. I'm also a fan of using t, 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 of s and S are just a couple of pages down from x.

In other words, :help is your friend. Read and learn.

眸中客 2024-12-09 04:02:12

使用c{motion}命令:

  1. cf_ - 更改为第一个“_”(包括);
  2. ct_ - 更改为第一个“_”(不包括);
  3. cw - 更改第一个单词;

该单词由iskeyword变量确定。使用 :set iskeyword? 检查并删除任何“_”,例如 :set iskeyword=@,48-57,192-255
顺便说一句,如果您想要更多信息,请参阅:help c:helpmotion

Use c{motion} command:

  1. cf_ - change up to the first '_' (including);
  2. ct_ - change up to the first '_' (excluding);
  3. cw - change the first word;

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.

南巷近海 2024-12-09 04:02:12

我认为 3cl 就是你想要的。它向右改变 3 个字符。我会输入 ct_del,但这不是您要求的

I think 3cl is what you want. It changes 3 characters to the right. I'd type ct_del<esc>, but that's not what you asked

终遇你 2024-12-09 04:02:12

c3  ('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 or l 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.

夜访吸血鬼 2024-12-09 04:02:12

如果作品长度相同,您可以使用 R 命令将您之前输入的内容替换为您输入的内容。

If the works have the same length you can use the R command which replaces what you had previously with what you type.

薔薇婲 2024-12-09 04:02:12

给出的其他答案使用数字。当文本较长时,就更容易不必计数。例如,我经常在 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 case r= 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文