Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM adds a character to a newline on hitting enter

Tags:

vim

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 "\033]12;red\007"
"   let &t_SI = "\033]12;orange\007"
"   let &t_EI = "\033]12;red\007"
"   autocmd VimLeave * :!echo -ne "\033]12;red\007"
"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?

like image 434
Jossie B Avatar asked Jun 22 '12 10:06

Jossie B


2 Answers

It looks like automatic comment insertion.

Take a look at :help formatoptions and :set formatoptions. These are probably being set by file type.

like image 145
Ken Avatar answered Oct 02 '22 07:10

Ken


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.

like image 42
Nolen Royalty Avatar answered Oct 02 '22 06:10

Nolen Royalty