VIM adds a character to a newline on hitting enter
I looked around but haven't found an answer to this. I have a CentOS 6.2 server running with the same .vimrc as my CentOS 5.8 server, however when I hit enter in VIM on my 6.2 server, it adds the first character of the previous line if it's a certain character (% or # are the ones I've seen). This is what happens in VIM (The seconds lines are right after hitting enter, but without typing anything else):
# <enter>
#
% <enter>
%
Here's my .vimrc:
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set number
imap jj <Esc> " Professor VIM says '87% of users prefer jj over esc', jj abrams disagrees
" Indenting *******************************************************************
set ai " Automatically set the indent of a new line (local to buffer)
set si " smartindent (local to buffer)
" Cursor highlights ***********************************************************
"set cursorline
"set cursorcolumn
" Set an orange cursor in insert mode, and a red cursor otherwise.
" Works at least for xterm and rxvt terminals.
" Does not work for gnome terminal, konsole, xfce4-terminal.
"if &term =~ "xterm|rxvt"
" :silent !echo -ne " 33]12;red 07"
" let &t_SI = " 33]12;orange 07"
" let &t_EI = " 33]12;red 07"
" autocmd VimLeave * :!echo -ne " 33]12;red 07"
"endif
" Searching *******************************************************************
set hlsearch " highlight search
set incsearch " Incremental search, search as you type
set ignorecase " Ignore case when searching
set smartcase " Ignore case when searching lowercase
" Colors **********************************************************************
"set t_Co=256 " 256 colors
set background=dark
syntax on " syntax highlighting
"colorscheme darkzen
Ran a diff against it and the one on my 5.8 server (where I don't have this problem) and there was no difference at all. Any idea why this may be happening?
It looks like automatic comment insertion.
Take a look at :help formatoptions and :set formatoptions. These are probably being set by file type.
Run verbose set formatoptions
. You should get back a string that contains 'r', which Automatically inserts the current comment leader after hitting <Enter> in Insert mode
. The verbose
bit should point you at the file(likely a filetype plugin) who is the culprit.
I prevent vim from hijacking my formatoptions via the autocommand au FileType * set formatoptions=lq
in my vimrc. Most of the options drive me absolutely crazy, although r
and o
are by far the worst.
上一篇: Fortran阵列内存管理
下一篇: VIM在回车中添加一个字符到换行符