简体   繁体   English

Vim:猛拉并粘贴线并保持柱子的位置

[英]Vim: yank and paste line and maintain column postition

Background: I am editing a reStructuredText table in vim. 背景:我正在vim中编辑reStructuredText表。 I would like to yank a line and paste it. 我想抽一条线并贴上它。 The line only contains cell vertical delimiters ( | ) so this operation corresponds to giving an existing row one more line of space in the source, but doesn't alone affect the output. 该行仅包含单元格垂直分隔符( | ),因此此操作对应于在源中为现有行提供一行空格,但不会单独影响输出。 A simple yyP or yyp , puts the cursor to column 1 after the operation. 一个简单的yyPyyp ,在操作后将光标置于第1列。

Q: Is there an easy way to "yank and paste a line" and keep the cursor in the same column after the operation as before it? 问:有没有一种简单的方法可以“拉出并粘贴一条线”并将光标保持在操作之后的同一列中?

After I wrote the question, it dawned on me to use a mark, and indeed that works: I can do mayyP and then `a to jump back to the desired column. 在我写完这个问题之后,我mayyP使用了一个标记,这确实有效:我可以做mayyP然后`a跳回到所需的列。 That's a bit long though. 虽然这有点长。 So the question is, can I do this with less keystrokes? 所以问题是,我能用更少的击键来做到这一点吗?

Edit: As Shahbaz rightly points out, I can just write an alias, now I know how to do what I want. 编辑:正如Shahbaz正确地指出的那样,我可以写一个别名,现在我知道如何做我想要的。 I am still interested in any shorter way that uses standard commands, in case I am missing some functionality that I should know about. 我仍然对使用标准命令的任何更短的方式感兴趣,以防我缺少一些我应该知道的功能。

As @romainl says, you should :set nostartofline (or :set nosol for short). 正如@romainl所说,你应该:set nostartofline (或者:set nosol简称:set nosol )。 Then, instead of yyp , use the :copy command: 然后,使用:copy命令而不是yyp

:copy .
:copy -

If :copy is too long, you can use :co or :t . 如果:copy太长,您可以使用:co:t If you do not use any ex commands in between, then you can repeat the command with @: and then with @@ . 如果您之间不使用任何ex命令,则可以使用@:然后使用@@重复命令。

:help :copy
:help @:
:help @
:set nostartofline

请参阅:help startofline

You could record a simple macro like 你可以记录一个简单的宏

qamayyP`aq

This writes your command to the register a and lets you replay it with the command @a . 这会将您的命令写入寄存器a并允许您使用命令@a重放它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM