How do i prevent neovim commenting out next line after a comment line?

When I comment out some line and hit enter neovim automatically comments the next line out. This is particularly problematic when pasting from the clipboard. If the snippet contains comments neovim goes ahaed and comments everything out after that point. How do I disable this “smart commenting”!!! ?

2 Likes

Just figured it out.

TLDR
set formatoptions-=cro

see following for details

:h 'formatoptions'
:h fo-table
1 Like

I had the same issue! Most people I know do too. I feel like it should be defaults.

Use :set paste to disable vim’s various helper features (auto comment, auto indent, auto line-wrapping, etc) when pasting while in insert mode. That way you can toggle everything at once while still keeping these features regularly. :set nopaste to go back.

I have neovim configured to paste from my system clipboard so i never need to toggle paste mode so i just p normally.

1 Like

wow this is particularly helpful thanks :slight_smile:

In my ~/.config/nvim/after/ftplugin/lua.lua I have:

 vim.opt_local.formatoptions:remove({ 'r', 'o' })
2 Likes

I did what voyeg3r did but I had to do it like this in my ~/.config/nvim/lua/vim-options.lua

vim.api.nvim_create_autocmd("FileType", {
  pattern = "*",
  callback = function()
    vim.opt_local.formatoptions:remove({ 'r', 'o' })
  end,
})

1 Like