I have a mapping in my vimrc that downwardly comments out regions of c code:
nmap comc :normal! I//
Since the \'normal\' ex command
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.