我通常使用标记来剪切/粘贴Vim.
要在第4行和第12行之间抽取文本,我执行以下操作:
mx以放置名为x的标记y'x以在第4行和第12行之间抽出文本完成此操作后,光标移回第4行.
有没有办法让光标停留在原位(不移回标记)?
如果有人有更好的方法来做同样的事情,那也会很棒......
提前致谢!
更新:
我使用FDinoff的答案来创建一个映射,让我成为一个快乐的露营者:
nnoremap YY y'x<C-O>
Run Code Online (Sandbox Code Playgroud)
这从光标到名为x的标记,然后将光标返回到它所在的位置.
这已经为我节省了大量时间.再次感谢!
The reason you jump to line 4 is because you are using yank with a backwards motion.
*y* *yank*
["x]y{motion} Yank {motion} text [into register x]. When no
characters are to be yanked (e.g., "y0" in column 1),
this is an error when 'cpoptions' includes the 'E'
flag.
Run Code Online (Sandbox Code Playgroud)
The motion in question is 'x which is jump to mark x. The cursor is moved to the beginning of the yanked part which in this case is line 4 since you were yanking from line 12.
However things you could do.
使用范围用于前命令行模式.范围是.(当前行)到'x(标记x).如果范围是向后的,请问你是否意味着另一个方向.这不会移动光标.:.,'xy
或者你可以使用<C-o>遗嘱将你跳回到你跳过的最后一个地方.(评论中提到过.)
或者你可以使用']或`].这些命令会跳转到最后一个被拉动的文本的最后一个字符.