bsr
bsr

Reputation: 58712

Vim map <D-/> to comment code

I installed nerd commenter, but couldn't make it work with the key bindings I used to. I don't need to use the above plugin, but what I am trying to acheive (In MAC OSX)

  1. map (command + /) to toggle comment (//) of the current line (in Insert mode atleast)
  2. Do the same on all lines if multiple lines are selected.
  3. It is great if multiple lines are selected to use the block comment (/* .. */)

thanks for any help.

EDIT: below mappings kind of solved 1 and 2. Now, I wish I could use block comment when select multiple lines, and (//) otherwise.

imap <D-/> <esc>,c<space>i
vmap <D-/> ,c<space>gv
map <D-/> ,c<space>

Upvotes: 3

Views: 661

Answers (1)

Hassek
Hassek

Reputation: 8995

this should work:

map <D-/> \c<space><CR>
imap <D-/> \c<space><CR>

or for sexy comments (aka /* */):

map <D-/> \cc<space><CR>
imap <D-/> \cc<space><CR>

you can check all the possible comments maps writing :help NERDCommenter and just remap them to what you like.

Upvotes: 3

Related Questions