繁体   English   中英

Vim 如何复制到真实(非相对)行号

[英]Vim how to copy to a real (no relative) line number

我正在使用 NeoVim,但对于这种情况,我认为如果我们谈论 vim 是一样的。 我已经设置了相对行号( set nu rnu ),并且我知道如何从我当前有光标的行复制到带有yxj的行 x,但是我需要复制的行数比我看到的要多,所以我首先转到第 247 行,然后我回到第 127 行,我不知道是否有办法指定我想复制到第 247 行(当然不减去)。

问候

相关文档是:help change.txt 我将突出显示change.txt帮助文档的:help copy-move部分中出现的一些命令(那里还有更多!)。

您可以使用命令行指定要抽出的行(即复制,请参阅:help :y ):

:127,247y

它也适用于相对数字(和模式 - 请参阅:help range ):

" yank lines 25 before cursor through 3 lines after
" cursor
:-25,+3y

此外,如果您知道要放置它们的位置,可以使用t命令(请参阅:help :t ):

" copy lines 10 before cursor through 2 lines after
" cursor to after 5 lines after the cursor
:-10,-2t+5

您甚至可以混合和匹配相对和绝对行(和模式 - 请参阅:help range ):

" copy from line 23 through to 10 lines before cursor to
" line 51
:23,-10t51

为了完整起见,可以使用m命令移动(即剪切和粘贴行,请参阅:help :t ):

" move lines 12 before the cursor through to the current
" line to line 27
:-12,.m27

traces.vim 插件

我发现这个插件非常好——它会在你在命令行上键入 Ex 命令时突出显示它们的范围(并显示:substitute命令在你编写文件时将如何影响你的文件)。 它真的帮助我开始更多地使用命令行。 我的 vimrc 中有这个:

" fyi: there is extensive help documentation that's not on the github page 

"immediately highlight numerical ranges once you put the comma :N,N
let g:traces_num_range_preview = 1

" window used to show off-screen matches (just 5 since I only want the gist).
let g:traces_preview_window = "below 5new"

" if value is 1, view position will not be changed when highlighting ranges or
" patterns outside initial view position. I like this since I see it all in the
" preview window setting above
let g:traces_preserve_view_state = 1
  • 移至第 247 行,
  • 通过ma设置标记,例如a
  • 移至第 127 行
  • 从那里拉到标记y'a

总而言之: 2 4 7 g g m a 1 2 7 g g y ' a

暂无
暂无

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

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