VIM Editor Notes
Some notes about the configuration of the VIM Editor. I like to use Vim as an IDE for C, Python, C++ development and HTML editing.
Contents
code completion
Are there nice code completion plugins? Doing parameter type suggestions for C/C++ and showing documentation for Python would be cool!
C++
Tip: C++ code completion
Plugin: OmniCppComplete (shows in and output parameter types)
vimrc file
An example VIM configuration file (I am using this). It also configures the Project Plugin and sets a few mappings to use it. Filename for linux: ~/.vimrc):
" GUI Options For GVim:
" #####################
" Default guioptions are "aegimrLtT"
set guioptions-=T "remove Toolbar
set guioptions-=m "remove menubar (menu is still accessible by <F10>)
" set font and key mappings for two different font sizes
set guifont=Bitstream\ Vera\ Sans\ Mono\ 10
nmap <S-F11> :set<Space>guifont=Bitstream\<Space>Vera\<Space>Sans\<Space>Mono\<Space>10<CR>
nmap <S-F10> :set<Space>guifont=Bitstream\<Space>Vera\<Space>Sans\<Space>Mono\<Space>8<CR>
" Filetype Things:
" ################
colorscheme candycode
syntax on "switches filetype detection and syntax highlighting on
set nowrap
" Modeline for secure identification: /* vim: set filetype=TYPE : */
"filetype on "FileType event triggering on, loads filetype.vim
"filetype plugin on "loads ftplugin.vim
"filetype indent on "automatically select indentation type depending on file
filetype plugin indent on "replaces the three lines above
" If no indent file is available:
" 'autoindent' use indent from previous line CTRL-T adds indent CTRL-D removes one
" 'smartindent' extra level of indentation for each { and any of the words in 'cinwords'
" 'cindent' smarter then smartindent
" Tab Things:
" ###########################
" All is set to never use tab-chars!
set softtabstop=4 "number of spaces inserted with <Tab> and deleted with <BS>
set shiftwidth=4 "set width of single indentation to 4. Use with ">>" or ">"
set expandtab "insert '[soft]tabstop' spaces with <Tab> key (never use tab-chars)
set smarttab "'shiftwidth' spaces indentation with <Tab>. Elsewhere '[soft]tabstop' spaces
"# For the use of tab-chars read and eventually uncomment the following two lines:
"#set softtabstop=4 "with expandtab=off replaces 4 spaces with a tab-char
"#set tabstop=4 "makes one tab-char apear like 4 spaces on screen. default: 8
"Tip: use command :retab [NUM] with expandtab=on to replace all tabs in with NUM spaces.
" Shortcuts:
" ##########
" Navigation in buffer tabs:
map <C-Tab> :tabnext<CR>
imap <C-Tab> :tabnext<CR>
map <S-Tab> :tabprev<CR>
imap <S-Tab> :tabprev<CR>
" Make some use of keys on a german Keyboard:
" save:
nmap ü :w<CR>
" change working directory to path of the current file in the buffer:
nmap ö :cd<Space>%:h<CR>
" next window:
nmap ä <C-w><C-w>
" one window up:
nmap ü <C-w><C-k>
" yank a word:
map ß yaw
" Window Steuerung:
" TODO Fenster maximieren:
" Settings For Project Plugin:
" ############################
" This section works only with the project plugin:
" http://www.vim.org/scripts/script.php?script_id=69
let g:proj_flags="imstLS"
nmap <silent> <F11> <Plug>ToggleProject
nmap <silent> <F8> :Project<CR>
filetype plugins
If a file is loaded into a buffer, vim is executing scripts in .vim/ftplugin beginning with <FILETYPE>_ (see config file above for how to switch this feature on).
Python
File .vim/ftplugin/python_keymappings.vim:
map <C-p><C-p> :w<CR>:!python<Space>%<CR> imap <C-p><C-p>> <ESC>:w<CR>:!python<Space>%<CR>
C/C++ with makefile
File .vim/ftplugin/cpp_keymappings.vim and .vim/ftplugin/c_keymappings.vim:
map <C-p><C-p> :w<CR>:make<CR> imap <C-p><C-p> <ESC>:w<CR>:make<CR>