5

On Vim, when I want to comment multiple lines I always use the following procedure:

1. select the first caracter of your block
2. press Ctrl+V ( this is rectangular visual selection mode)
3. type j for each line more you want to be commented
4. type Shift-i (like I for "insert at start")
5. type // (or # or " or ...)
6. you will see the modification appearing only on the first line
7. IMPORTANT LAST STEP: type Esc key, and there you see the added character appear on all lines

This works fine on Vim. However, on NeoVim it doesn't work at all... Can I comment multiple lines on NeoVim without using any specific plugin for that?

6
  • 3
    This is fundamental functionality that Neovim absolutely implements. You may need to debug your vimrc/plugins: How do I debug my vimrc file?
    – B Layer
    Commented Jun 19, 2021 at 20:02
  • @BLayer Thanks, you're right, it works on NeoVim. I had a problem on my init.vim file from NeoVim, I found a line with inoremap <Esc> <Nop>... Taking it out solved the problem. However, the command nvim -u NONE -U NONE -N file didn't work for initializing NeoVim without any configuration... I think the syntax is different in this case...
    – raylight
    Commented Jun 19, 2021 at 20:17
  • How about --clean (click that) as noted at the end of the linked answer (that I just added yesterday)? That's basically -u NONE -i NONE plus additional sterilization. It'll also tell you why you don't have/need Vim's -N (which essentially does :set nocompatible).
    – B Layer
    Commented Jun 19, 2021 at 20:34
  • 1
    @BLayer Cool, both nvim -u NONE -i NONE file and nvim --clean file work fine for testing nvim without the configurations.
    – raylight
    Commented Jun 19, 2021 at 20:44
  • @raylight let's move the answer into an answer that you can accept :)
    – D. Ben Knoble
    Commented Jun 19, 2021 at 21:51

1 Answer 1

4

As stated in the comments, this functionality is already implemented on NeoVim by default. The problem was because my init.vim file from NeoVim had the line inoremap <Esc> <Nop>, which was interfering on the functionality of accomplishing the step 7 that I said on my question. Taking out this line from the configuration file solved the issue.

One way of debugging if the problem is with the configuration or not when this kind of problem happens can be found on this answer on "How do I debug my vimrc file?". Basically, we can open a file with nvim -u NONE -i NONE randomFileName or nvim --clean randomFileName for checking how Vim or Neovim behave without any additional configuration. So we can check if the problem is on the configuration file or if it's something else.

2
  • I was able to solve the problem by pressing Esc twice.
    – Okoyos
    Commented Sep 16, 2021 at 7:11
  • I don't have the inoremap line in my init.vim or .vimrc file but I have the same problem, pressing Esc twice doesn't work for me either. anyone know why?
    – HelloThere
    Commented Jul 22, 2022 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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