In Vim, is there a way to copy the current line number into a buffer?

风流意气都作罢 提交于 2019-12-03 13:48:56
Gowri

put this in your vimrc

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

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

So the magic line is:

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

The reason:

  1. The register * hold the clipboard
  2. line('.') holds the current line number

Of course you can map that function to a shortcut:

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

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

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.

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

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

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!