search

Home  >  Q&A  >  body text

Repeat the mapping command in vim view mode

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?

PHP中文网PHP中文网2844 days ago794

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-05-16 16:44:01

    Now I know

    command! -range=% EchoVisual :!sed -n <line1>,<line2>p %:p
    vmap <leader>e :EchoVisual<CR>
    

    reply
    0
  • 阿神

    阿神2017-05-16 16:44:01

    command! -range=% EchoVisual :<line1>,<line2>p | echo expand('%:p')
    vmap <leader>e :EchoVisual<CR>
    

    How?

    reply
    0
  • Cancelreply