Vim auto indenting

I used to get annoyed when pasting text into a Vim window as each line would indent one more tab than the last line.

To fix it I used to add set noautoindent in /etc/vimrc, however this unsurprisingly turns off auto indenting, which is a useful feature for normal typing.

Today I came up with a definitive solution to this by setting a key binding for ‘pastetoggle’. Now in vimrc is the line:

set pastetoggle=<F11>

..meaning that should I need to paste in some formated text I simply press F11 when in insert mode to enter paste mode, paste my text in and then F11 again to exit paste mode (but still be in insert).

One could also do :set paste and :set nopaste, but this was far too much typing for my liking.

Note: This is working for me in Vim 7.0

Vim: Enough tabs already

Scenario:

You are connected to a Linux webserver via a Windows terminal client such as PuTTy. You copy some text to paste into a Vim document open on the remote machine and you get tab hell:

Here’s an example of something I pasted in tonight:

[code]
ServerAdmin webmaster@host.some_domain.com
DocumentRoot /home/bealers/www
ServerName bealers.dev
ErrorLog /var/log/apache/bealers.dev-error.log
CustomLog /var/log/apache/bealers.dev-access.log common

Options Indexes

[/code]

To fix this globally you can edit, as root, /etc/vim/vimrc (or similar) so that this line is commented out, or add it if not there:
[code]set autoindent[/code]

else edit your vimrc file ~/.vimrc

Related:
http://www.vim.org/tips/tip.php?tip_id=330

~/.vimrc

I was playing around a on virgin DSVR (vs300) account for a few hours during the week, just getting php and mysql ready for use. vi was being really annoying, giving me the dreaded A B C D routine when the arrow keys were pressed in insert mode.

vim in compatible mode, I could’nt find a vimrc anywhere so I placed this into ~/.vimrc

set nocompatible
set backspace=indent,eol,start
set background=dark
syntax on
set history=50
set ruler
set noautoindent

much better!