Celso Suzuki
Celso Suzuki

Reputation: 441

How to disable the auto comment in shell script vi editing?

I'm using vi(m) to edit a shell script and when I insert a comment and type , the new line came with a comment already.
How can I disable it ?

Ex :
# When I type enter, the comment simbol # below is inserted automaticaly.
#

Upvotes: 44

Views: 39884

Answers (5)

pavan kota
pavan kota

Reputation: 61

You're looking for the option:

:see paste

I have gone through many blogs where there was an option:

:see formatoptions-=cro

Which did not work!

Upvotes: 3

Matteo
Matteo

Reputation: 8142

I found some links solving your issue:

  • http://www.linuxquestions.org/questions/linux-general-1/vim-auto-comment-696916/

    You're probably looking for this command

    :set paste

    Or you can add this line to your ~/.vimrc (which will allow you to toggle between paste and nopaste with Ctrl+P)

    nm <C-P> :se invpaste paste?<CR>

  • http://ubuntuforums.org/showthread.php?t=833353

    to resolve problem with inserting some text/code in vim with comments you can just add in your .vimrc file this line:

    set pastetoggle=

    that will make set paste on pasting and set nopaste when it's done..

  • http://vim.wikia.com/wiki/Disable_automatic_comment_insertion

    To disable it just once for the current session:

    :set formatoptions-=cro

    To disable for all files and sessions, use this:

    autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o

    This sets up an auto command that fires after any filetype-specific plugin; the command removes the three flags from the 'formatoptions' option that control the automatic insertion of comments. With this in your vimrc, a comment character will not be automatically inserted in the next line under any situation.

    Use this command to check your format options:

    :set formatoptions?

Hope it's useful, let me know if you got it clear. Bye

Upvotes: 16

Jay Dorsey
Jay Dorsey

Reputation: 3662

The vi stack exchange documents another excellent option:

https://vi.stackexchange.com/a/1985/12256

You can add something like below to your .vimrc file to ensure shell scripts won't automatically insert the comment leader.

au FileType sh setlocal fo-=c fo-=r fo-=o

The vim documentation will tell you what each of the options (c, r, o) mean.

http://vimdoc.sourceforge.net/htmldoc/change.html#fo-table

Upvotes: 1

SergioAraujo
SergioAraujo

Reputation: 11840

This feature is useful, how about just pressing Ctrl-u in insert mode? it will delete everything until the beginning of the line. By doing that you do not lose auto comments.

See more here and here:

Upvotes: 1

auxten
auxten

Reputation: 912

I was finding the same answer, try

:set paste

this may help

Upvotes: 72

Related Questions