在Vim中,有没有办法将当前行号复制到缓冲区?

时间:2021-03-30 19:19:23

When using gdb and Vim, often I want to stop on a particular line. Normally in Vim I copy-paste the line number showing on the rule area to the gdb session. It'd save me a lot of hassle if I could use something like "+<magic-incantation> to copy the line number of the current cursor position into the xclipboard buffer. Is this possible?

使用gdb和Vim时,我经常想停在特定的行上。通常在Vim中,我将规则区域上显示的行号复制粘贴到gdb会话。如果我可以使用类似“+ ”的东西将当前光标位置的行号复制到xclipboard缓冲区中,这将为我省去很多麻烦。这可能吗?

4 个解决方案

#1


10  

put this in your vimrc

把它放在你的vimrc中

map ,n <Esc>:let @*=line(".")<CR>

then using ,n will copy the current line number into the clipboard

然后使用,n会将当前行号复制到剪贴板中

#2


6  

So the magic line is:

所以神奇的界限是:

 :call setreg('*', line('.'))

The reason:

  1. The register * hold the clipboard
  2. 寄存器*持有剪贴板

  3. line('.') holds the current line number
  4. line('。')保存当前行号

Of course you can map that function to a shortcut:

当然,您可以将该功能映射到快捷方式:

nmap ,ln :call setreg('*', line('.'))<CR>

#3


0  

Also, to use GDB from within vim, you may want to check out some of the gdb scripts on vim.sourceforge.net -

另外,要在vim中使用GDB,您可能需要查看vim.sourceforge.net上的一些gdb脚本 -

#4


-1  

Not sure if this is what you're after but have you tried using markers?

不确定这是否是您所追求的,但您尝试过使用标记吗?

Put the cursor on the line you want, then enter m and a letter, say a.

将光标放在所需的行上,然后输入m和一个字母,例如a。

Entering 'a will take you to the line containing the marker.

输入'a将带您到包含标记的行。

Entering `a will take you to the actual letter that you marked in the line.

输入'a将带您到该行中标记的实际字母。

Hmm, just thinking a bit further, this must be available as the line number is available for use in various functions, e.g. for use in the status bar.

嗯,只是想一想,这必须是可用的,因为行号可用于各种功能,例如,用于状态栏。

#1


10  

put this in your vimrc

把它放在你的vimrc中

map ,n <Esc>:let @*=line(".")<CR>

then using ,n will copy the current line number into the clipboard

然后使用,n会将当前行号复制到剪贴板中

#2


6  

So the magic line is:

所以神奇的界限是:

 :call setreg('*', line('.'))

The reason:

  1. The register * hold the clipboard
  2. 寄存器*持有剪贴板

  3. line('.') holds the current line number
  4. line('。')保存当前行号

Of course you can map that function to a shortcut:

当然,您可以将该功能映射到快捷方式:

nmap ,ln :call setreg('*', line('.'))<CR>

#3


0  

Also, to use GDB from within vim, you may want to check out some of the gdb scripts on vim.sourceforge.net -

另外,要在vim中使用GDB,您可能需要查看vim.sourceforge.net上的一些gdb脚本 -

#4


-1  

Not sure if this is what you're after but have you tried using markers?

不确定这是否是您所追求的,但您尝试过使用标记吗?

Put the cursor on the line you want, then enter m and a letter, say a.

将光标放在所需的行上,然后输入m和一个字母,例如a。

Entering 'a will take you to the line containing the marker.

输入'a将带您到包含标记的行。

Entering `a will take you to the actual letter that you marked in the line.

输入'a将带您到该行中标记的实际字母。

Hmm, just thinking a bit further, this must be available as the line number is available for use in various functions, e.g. for use in the status bar.

嗯,只是想一想,这必须是可用的,因为行号可用于各种功能,例如,用于状态栏。