0

I tried out answers in What's a quick way to comment/uncomment lines in Vim?, but they don't work. Pressing shift i on visual mode after selection just brings me in insert mode. I run it with --noplugin, no use.

Community
  • 1
  • 1
proxy
  • 846
  • 2
  • 11
  • 24
  • 2
    The question you refer answers your question, it should work. Before doing `shift i` you need to do `Ctrl V` to go to the visual block selection mode, you should see that when you move the cursor, you select the block (rectangle area) and not the whole lines. Then `shift i` should jump to the start of the block and enter the insert mode. Once you finish typing the text and press `Esc`, the text you typed should appear in every line of the block you had selected. – Borys Serebrov Jan 24 '16 at 09:50
  • Possible duplicate of [What's a quick way to comment/uncomment lines in Vim?](http://stackoverflow.com/questions/1676632/whats-a-quick-way-to-comment-uncomment-lines-in-vim) – proxy Jan 24 '16 at 14:01
  • @BorisSerebrov yeah you write i was inattentive and was doing `shift V` – proxy Jan 24 '16 at 14:32

2 Answers2

2

You might need to take visual block before proceeding , Ctrl-v to use it. More at help blockwise-visual

Then, use any nagivation keys like h,j,k,l, followed by I, then insert your comment character like # or // and finalize by Esc.

This should comment whole block.

To uncomment, repeat the same operation of visual block and navigation but replace I by any delete operation like x for # or 2x for //. Hope this helps

dlmeetei
  • 9,905
  • 3
  • 31
  • 38
1

There are many ways to comment/uncomment in Vim. Anyway, assuming "C++-style" comments, eg. // foobar

Commenting a single line

I// <Esc>

Uncommenting a single line

^dw

Commenting several lines

vjjj
:'<,'>norm! I// <CR>

or

<C-v>jjj
I// <Esc>

Uncommenting several lines

vjjj
:'<,'>norm! ^dw<CR>

or

<C-v>jjjllld
romainl
  • 186,200
  • 21
  • 280
  • 313