Vim 如何复制到一个真实的(无相关的)行号
Vim how to copy to a real (no relative) line number
我正在使用 NeoVim,但对于这种情况,我认为如果我们谈论 vim 也是一样的。我已经设置了相对行号(set nu rnu
)并且我知道如何从我当前有光标的行复制到带有yxj
的x行,但是我需要复制比我看到的更多的行,所以我先转到第247行,然后回到第127行,不知道有没有办法指定我要复制到第247行(当然不减)。
此致
- 移动到第 247 行,
- 设置一个标记,例如
a
,来自 ma
- 移动到第 127 行
- 从那里猛拉到标记
y'a
总而言之:247ggma127ggy'a
相关文档是: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 插件
我发现 this plugin 非常好 - 它会像您一样突出显示 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
我正在使用 NeoVim,但对于这种情况,我认为如果我们谈论 vim 也是一样的。我已经设置了相对行号(set nu rnu
)并且我知道如何从我当前有光标的行复制到带有yxj
的x行,但是我需要复制比我看到的更多的行,所以我先转到第247行,然后回到第127行,不知道有没有办法指定我要复制到第247行(当然不减)。
此致
- 移动到第 247 行,
- 设置一个标记,例如
a
,来自ma
- 移动到第 127 行
- 从那里猛拉到标记
y'a
总而言之:247ggma127ggy'a
相关文档是: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 插件
我发现 this plugin 非常好 - 它会像您一样突出显示 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