首页 > vim 视图模式下重复执行映射命令

vim 视图模式下重复执行映射命令

我写了一个vim函数来打印我选中的几行文字并进行快捷键映射,代码如下:

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>

但是在实际执行的时候,每次我按<leader>e时EchoVisual函数会重复执行n次,n的大小同我选择的行数是一样的,请问这是什么问题呢?该如何解决呢?


现在知道了

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

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

如何?

【热门文章】
【热门文章】