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

浏览:42日期:2023-07-26

问题描述

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

function! EchoVisual()let st= getpos('’<')[1]let ed= getpos('’>')[1]execute ’!sed -n ’.st.’,’.ed.’p ’.expand(’%:p’)endfunctionvmap <leader>e :call EchoVisual()<CR>

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

问题解答

回答1:

现在知道了

command! -range=% EchoVisual :!sed -n <line1>,<line2>p %:pvmap <leader>e :EchoVisual<CR>回答2:

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

如何?

相关文章: