Yank file path with line no from vim to the system clipboard

I would like yank -

  • The full path to the file, for example. c: \ foo \ bar \ file.txt: 94 with its line no

I would also like to paste it into my system clipboard, so I will use the "+" register for this.

Can you suggest me a possible way to do this?

+6
source share
1 answer

If you try yank c:\foo\bar\file.txt:94 when you are on line 94 c:\foo\bar\file.txt , you can use the following statement to set the + register to
<file_path>:<line_number>

 :let @+=expand("%") . ':' . line(".") 

expand("%") is the current file name
line(".") - current line number

Display example

 nnoremap <leader>y :let @+=expand("%") . ':' . line(".")<CR> 
+10
source

Source: https://habr.com/ru/post/948823/


All Articles