How to comment current select , copy the select and move it to after the selection

i have a code

async (url, options) => {
  delete options.headers
  delete options.headers
}

i want to

  1. select all the code
  2. press hot key
  3. comment current select
  4. copy the select and move it to after the selection
// async (url, options) => {
//  delete options.headers
//  delete options.headers
// }
async (url, options) => {
  delete options.headers
  delete options.headers
}

have one command or key implment ?

Are you using any commenting plugin already?
If you use something like numtostr/comment.nvim you can do mapping like this:

vmap X y'>pgvgcc<esc>'>j

Then when you press X after selecting text it will do what you wanted.

Explanation:
y - copy selection
'> - go to end of selection
p - paste after selection
gv - go to select mode again
gcc - comment selection (this is why you need comment.nvim or similar)
<esc> - normal mode
'> - go to end of selection
j - go line below (first line of uncommented block)

1 Like

Using “numToStr/Comment.nvim” you can do:

yip  ......................... copy current paragraph
gbip  ....................... comment current paragraph
} ............................ jump to the end of current paragraph
p ............................ paste