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

Ass*_*ror 1 vim

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

问候

mat*_*ttb 5

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

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

:127,247y
Run Code Online (Sandbox Code Playgroud)

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

" yank lines 25 before cursor through 3 lines after
" cursor
:-25,+3y
Run Code Online (Sandbox Code Playgroud)

此外,如果您知道要将它们放在哪里,可以使用以下t 命令(请参阅:help :t):

" copy lines 10 before cursor through 2 lines after
" cursor to 5 lines after the cursor
:-10,-2t+5
Run Code Online (Sandbox Code Playgroud)

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

" copy from line 23 through to 10 lines before cursor to
" line 51
:23,-10t51
Run Code Online (Sandbox Code Playgroud)

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

" move lines 12 before the cursor through to the current
" line to line 27
:-12,.m27
Run Code Online (Sandbox Code Playgroud)

Traces.vim 插件

我发现这个插件非常好 - 当您在命令行上键入 Ex 命令时,它会突出显示 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
Run Code Online (Sandbox Code Playgroud)