vim config file with minimal changes compared to default debian squeeze:
aptitude install vim update-alternatives --set editor /usr/bin/vim.basic
" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below. If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed. It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
syntax on
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
" au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
" filetype plugin indent on
"endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
set number " display line numbers
set autoindent " copy the indentation from the previous line, when starting a new line
set tabstop=4 " Insert 4 spaces for a tab
set expandtab " To insert space characters whenever the tab key is pressed
set shiftwidth=4 " To change the number of space characters inserted for indentation
set pastetoggle=<F2> " disable/enable autoindent to paste without messing up formatting
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
map <C-n> :tabnext<CR>
To integrade available addons into vim the addon-manager is needed:
# 1st the manager is needed: aptitude install vim-addon-manager #2nd an addon can be installed: aptitude install vim-puppet #3rd activate the addon # (only for current user) vim-addons install puppet # (for all users system wide) vim-addons -w install puppet # list what is configured: vim-addons # Name User Status System Status editexisting removed removed justify removed removed matchit removed removed puppet installed removed
Undo a change:
u
Redo an undo:
ctrl-R
To change all the existing tab characters to match the current tab settings, use:
:retab
To convert only the current line to to match the current tab settings, use:
:.retab
To insert space characters when you press the tab key, set the 'expandtab' option. If you need a real tab charater with this option set, use Ctrl-V<Tab> key sequence
:set expandtab
To comment out a block of code (#): enter visual mode (V), then search & replace:
" comment out: :s/^/# / " remove comment: :s/^# //
Remove 4 spaces in front of (#) as below:
# Some comment(s)
# lorem ipsum
:s/^\s\{4}//g
the result will be:
# Some comment(s) # lorem ipsum
do the opposite, insert 4 spaces:
:s/^/ /g
Use tabs within vim.
Open two files at once in tabs:
vim -p file1 file2
Open a file into a new tab:
:tabf filename
Switch between tabs:
:tabn :tabp :tabfirst :tablast
Make switching tabs even easier:
# add the following line to your ~/.vimrc and you can press <ctrl><n> to switch between tabs! map <C-n> :tabnext<CR>
List tabs:
:tabs
Run a command in all open tabs (replace alle occurrences of “old” with “new”):
:tabdo %s/old/new/g
The big tab manual:
:help tab-page-intro