Alex Rivera | Logout

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

Asked 2008-11-17T11:02:40.000
11

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?

Edit
Report

2 Answers

12

put this in your vimrc

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

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

answered 2008-11-17T11:27:00.840
-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.

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.

answered 2008-11-17T11:11:51.790

Your Answer