I have selected a JS block such as following:

function map(xs: string[], cb: Function) : string[] {
  const result: string[] = [];
  for(let i = 0; i++; i < xs.length) {

  return result;

Now I want to go to the beginning of each line and comment out each line in the block (inserting // at the beginning of each line). How can I do this in the fastest way possible using text objects? I am aware that this is also possible by doing column selection Ctrl + V, <number>j, I, // and ESC sequence. But I want to do this in the fastest way possible.


2 Answers 2


You can try this:

  1. vip select paragraph
  2. <Ctrl-v> make selection blockwise
  3. I// insert // into begining of a selection block

enter image description here

PS: I would suggest to use vim-commentary plugin from Tim Pope where it would be simple gcip.


I think the fastest would be using the commentary plugin as Maxim Kim mentioned: just type gc since you already have the lines selected. But if you want another option using vanilla vim, you could try using regex substitution:


You can use other characters instead of &; I used that one because it's next to ^ on my keyboard. I use it instead of the standard / to avoid having to escape the slashes in the substitution, as in:


but that also works.

Not the answer you're looking for? Browse other questions tagged or ask your own question.