In insert-mode, I would like to extract the current line number I'm editing in a variable/memory/buffer, and to be able to paste it through a remapping.I know that :echo line(.) gives me the line number. I have found how to insert the line number at the beginning of each line, using :s/^/\=line(.).But I would like to have a remapping like ::inoremap \l <Esc>:echo line(.) > buffer<CR> pthat would extract the line number and paste it at my current cursor position.(Sources of previous searches :How to add permanent line numbers to a file?)
Extract line number as a variable to re-insert it
line numbers
This is a perfect use case for the expression register:inoremap <key> <C-r>=line(.)<CR>or:inoremap <expr> <key> line(.)See :help \=, :help i_ctrl-r, and :help <expr>.