I wrote a vim function to print the selected lines of text and map the shortcut keys. The code is as follows:
function! EchoVisual() let st= getpos("'<") let ed= getpos("'>") execute '! sed -n '.st.','.ed.'p '.expand('%:p') endfunction vmap <leader>e :call EchoVisual()<CR>
But in the actual implementation, every time I press
<leader>eWhen the EchoVisual function will be executed n times repeatedly, the size of n is the same as the number of rows I selected. what is the problem? How to solve it?
Now I know
command! -range=% EchoVisual :! sed -n <line1>,<line2>p %:p vmap <leader>e :EchoVisual<CR>