开发者

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 inse开发者_如何学编程rted automaticaly.

#


I was finding the same answer, try

:set paste

this may help


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


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:


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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜