2

Is it possible to surround a selected part of a line with /* and */?

start COMMENT ME end
start /*COMMENT ME*/ end
Hotschke
  • 4,740
  • 26
  • 37

3 Answers3

1

There is a plugin name NerdCommenter provide many ways of commenting, includes /* */: https://github.com/scrooloose/nerdcommenter

If you just need a quick solution, here is the macro which does the trick:

Update: let @j="viws/*<esc>pa */<esc>"

Let save it to your .vimrc file then using by moving the cursor at the word then @j.

Finn
  • 146
  • 3
0

The simple (redoable version, that messes * register) is

xnoremap µ s/* <c-r>" */<esc>

PS: this is quite certainly a duplicate

Luc Hermitte
  • 17,351
  • 1
  • 33
  • 49
0

You can use either of the following sequences of keystrokes from visual mode to comment out the currently selected text:

c/**/<Esc>hP

c/*<C-R>"*/<Esc>

(Note that the second of these is essentially the same as in Luc Hermitte's mapping. See :help i_CTRL-R if you're not sure how it works.)

Rich
  • 31,891
  • 3
  • 72
  • 139