Advanced Usage of Ranges with Vim Keymappings

后端 未结 2 1963
不知归路
不知归路 2021-01-23 11:26

I have a mapping in my vimrc that downwardly comments out regions of c code:

nmap comc :normal! I//

Since the \'normal\' ex command

2条回答
  •  别那么骄傲
    2021-01-23 11:58

    The behavior you requested is normally done with :h map-operator mapping. With this commenting 3 lines down will turn into comc2j though, but 3 lines up is now just as easy: comc2k.

    You can also use visual mode without changing your mapping at all: V2kcomc. You will have to add xnoremap with the identical lhs and rhs because nnoremap works only for normal mode. (And do not use nmap.)

    Third option is mapping - to something that moves {count} lines up and puts count back:

    nnoremap  - (v:count ? ":\\n" . (v:count-1) . 'k' . v:count : '')
    

    . This assumes you are writing 6-comc, not -6comc.

    // By the way, I would suggest The NERD Commenter if it comes to the plugin.

提交回复
热议问题