I wrote a vim function to print the selected lines of text and perform shortcut key mapping. The code is as follows:
function! EchoVisual()
let st= getpos("'<")[1]
let ed= getpos("'>")[1]
execute '!sed -n '.st.','.ed.'p '.expand('%:p')
endfunction
vmap <leader>e :call EchoVisual()<CR>
But during actual execution, every time I press <leader>e
, the EchoVisual function will be executed repeatedly n times. The size of n is the same as the number of rows I selected. What is this? What's the problem? How to solve it?
漂亮男人2017-05-16 16:44:01
Now I know
command! -range=% EchoVisual :!sed -n <line1>,<line2>p %:p
vmap <leader>e :EchoVisual<CR>
阿神2017-05-16 16:44:01
command! -range=% EchoVisual :<line1>,<line2>p | echo expand('%:p')
vmap <leader>e :EchoVisual<CR>
How?