inserting a new line below a comment in vim?

后端 未结 4 616
耶瑟儿~
耶瑟儿~ 2020-12-20 20:39

While inserting a new line below a comment in vim, the result tends to insert a \" at the start of the new line. It\'s probably a simple solution or reason why

相关标签:
4条回答
  • 2020-12-20 20:47

    If you’re editing a file of the vim filetype, Vim might by default insert the comment character (in Vimscript, this would be ") at the beginning of each new line you enter after a comment. As already mentioned, this is a result of Vim’s formatoptions setting.

    To turn this behavior off in the current file, run

    :set formatoptions-=ro
    

    To turn it off by default, add this to your ~/.vimrc:

    set formatoptions-=ro
    

    To turn it off for Vimscript files, add this to your ~/.vimrc:

    augroup filetype_vim
        autocmd!
        autocmd FileType vim setlocal formatoptions-=ro
    augroup END
    

    r and o are options which can be given to formatoptions. For the full list of possible options, run :help fo-table.

    0 讨论(0)
  • 2020-12-20 20:59

    I think this should work, regardless of your formatoptions settings.

    inoremap <CR> <CR><C-U>

    0 讨论(0)
  • 2020-12-20 21:12

    This behaviour is governed by the formatoptions variable.

    Use :h formatoptions to find out more.

    The following article might also be helpful: Disable automatic comment insertion.

    0 讨论(0)
  • 2020-12-20 21:12

    what command are you using to insert below?

    If you use the standard "o" keystroke while in Navigation mode, it should insert a new line immediately below whatever the cursor is on, and automatically place you into Insert mode, without inserting an extra "

    Similarly an uppercase "O" will insert a new line above whatever line the cursor is on, and place you in insert mode.

    0 讨论(0)
提交回复
热议问题