vim.tt

<h1>Vim cheats++</h2>
<h2>TOC</h2>
<ol>
    <li><a href="#vimrc">.vimrc</a></li>
    <li><a href="#ctags">Word/line completion and ctags</a></li>
    <li><a href="#misc">Misc</a></li>
    <li><a href="#insert_package_from_file">InsertPackageFromFile()</a></li>
    <li><a href="http://amix.dk/blog/viewEntry/130">Vim 7 - the graphical introduction</a></li>
</ol>

<h2 id="vimrc">.vimrc</h2>
<pre>
" basic settings
set autoindent
set backspace=indent,eol,start " more powerful backspacing
set clipboard=unnamed
set complete=.,w,b,u,t " skip grepping :S
set encoding=utf-8
set expandtab
set history=50 " keep 50 lines of command line history
set nobackup " Don't keep a backup file
set nowrap
set ruler " show the cursor position all the time
set shiftround
set shiftwidth=4
set showcmd
set softtabstop=4
set tabstop=8

" me like tabs
map ,e :tabedit &lt;C-R>=expand("%:h")&lt;CR>
map &lt;C-n> :tabnext&lt;CR>

" spelling
map ,s :setlocal spell spelllang=en_us " set spelling language
map &lt;F5> z= " check spelling

" pasting
nnoremap &lt;F2> :set invpaste paste?&lt;CR>
set pastetoggle=&lt;F2>

" gnome-terminal/something puts weird characters into my files
map ,f :%s/\%xa0/ /g&lt;CR>

" make vim jump to the last position when reopening a file
if has("autocmd")
  au BufReadPost * if line("'\"") > 0 && line("'\"") &lt;= line("$")
    \| exe "normal g'\"" | endif
endif

filetype plugin on " autoload plugins from $VIM/ftplugin/[filetype]/*
syntax on
</pre>

<h2 id="ctags">Word/line completion and ctags</h2>
<ul>
    <li><a href="http://amix.dk/blog/post/19329">Using ctags in Vim</a></li>
    <li><a href="http://vim.sourceforge.net/scripts/script.php?script_id=273">taglist.vim : Source code browser (supports C/C++, java, perl, python, tcl, sql, php, etc)</a></li>
    <li><a href="http://www.vim.org/scripts/script.php?script_id=1924">omniperl : omnicompletion for the perl language</a></li>
    <li><a href="http://vimdoc.sourceforge.net/htmldoc/tagsrch.html">Vim documentation: tagsrch</a></li>
</ul>

<dl>
    <dt>ctrl-n, ctrl-p</dt>
    <dd>Next/previous word completion</dd>
    <dt>ctrl-x ctrl-l (ctrl-n/p)</dt>
    <dd>Line completion</dd>
    <dt>ctrl-x ctrl-k</dt>
    <dd>Dictionary completion. Requires: <code>:set dictionary=/usr/share/dict/words</code></dd>
</dl>

<pre>
" autocomplete with tab/shift+tab
function! SuperCleverTab(direction)
    if strpart(getline('.'), 0, col('.') - 1) =~ '^\s*$'
        return a:direction == 1 ? "\&lt;Tab>" : "\&lt;S-Tab>"
    else
        if pumvisible()
            return a:direction == 1 ? "\&lt;C-N>" : "\&lt;C-P>"
        elseif &omnifunc != ''
            return "\&lt;C-X>\&lt;C-O>"
        elseif &dictionary != ''
            return "\&lt;C-K>"
        else
            return a:direction == 1 ? "\&lt;C-N>" : "\&lt;C-P>"
        endif
    endif
endfunction

inoremap &lt;Tab> &lt;C-R>=SuperCleverTab(1)&lt;CR>
inoremap &lt;S-Tab> &lt;C-R>=SuperCleverTab(-1)&lt;CR>

" left sidebar with overview of class/functions++
let s:Tlist_Ctags_Cmd = "/usr/bin/ctags"
let s:Tlist_WinWidth = 30
map &lt;F4> :TlistToggle&lt;cr>

" &omnifunc autocompletion (requires filetype plugin on)
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
</pre>

<h2>Misc</h2>
<dl>
    <dt>* and #</dt>
    <dd>Search forward/backward for the current word.</dd>
    <dt>%</dt>
    <dd>Will jump to the matching parenthesis/square bracket/curly brace.</dd>
</dl>
<ul>
    <li><a href="http://www.vim.org/scripts/script.php?script_id=23">EnhCommentify.vim : comment lines in a program</a></li>
</ul>

<h2 id="insert_package_from_file">InsertPackageFromFile()</h2>
<p>
    This method insert the package name of the current perl module you are editing.
</p>
<pre>
function! InsertPackageFromFile()
    let a:file = expand("%:p")
    let a:location = split(a:file, "/lib/")
    if len(a:location) == 2
        let a:location[1] = substitute(a:location[1], '/', '::', 'g')
        let a:location[1] = substitute(a:location[1], '.pm', '', '')
        execute "normal i" . a:location[1] 
    else
        echo "Could not find package name from '" . a:file ."'"
    endif
endfunction

map ,pp :call InsertPackageFromFile()&lt;CR>a
</pre>