"!!! makes use of marker ' " Sessions set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages " some conditional configs if has('mouse') set mouse=a endif if &t_Co > 2 || has("gui_running") syntax on set hlsearch "Highlight search results endif set nocompatible """""""""""""""" set history=50 " keep 50 lines of command line history set nonumber set relativenumber set langmenu=en_UK let $LANG = 'en_UK' source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim set guioptions-=r set guioptions-=R set guioptions-=l set guioptions-=L set gfn=Courier_New:h12:cANSI try set undodir=$HOME/.vimundo set undofile catch echom "Undofile doesn't work :(" endtry filetype plugin on filetype indent on set ruler set backspace=eol,start,indent set path+=** " Enable fuzzy search " STAAAAAARS set wildmenu "Menu for tab completion set enc=utf8 " Search Stuff set ignorecase set smartcase noh set incsearch set lazyredraw set magic "Who doesn't want to be a vim-wizard? set showmatch " Backup and file stuff set nobackup set nowb set noswapfile " Indentation, etc. set tabstop=2 set softtabstop=2 set shiftwidth=2 set noexpandtab set smarttab set autoindent set smartindent set smarttab set shiftwidth=2 set gdefault set wrap au BufEnter,BufRead * set linebreak set breakat=\ .,{ set display+=lastline set showbreak=+->\ set listchars=eol:¶,tab:»\ ,trail:. set modeline " Allows setting vim options in other files set statusline=(%n)\ %f\ [%M%R]\ [%Y]%=%l,%c%V\ %4.P set laststatus=2 set cmdheight=1 set timeoutlen=1200 " Clipboard and Copy/Paste things set clipboard=unnamed " Allow copying to and from OS clipboard noremap d "_d noremap d "_d noremap x "_x noremap x x " === GENERAL KEY MAPPINGS === let mapleader = "\\" noremap : noremap @: noremap Q @q nnoremap gQ noremap :w noremap :hide noremap :bdelete nnoremap :bnext nnoremap :bprevious noremap :setl number! noremap :setl relativenumber! noremap :setl autowriteall!:setl autowriteall? noremap :setl list! nnoremap ge nnoremap gE com! Setwd :cd %:p:h com! Removetrailingspaces :%s/\v(\\@t :Removetrailingspaces nnoremap :copy . nnoremap dx 0"_d$ nnoremap dcx 0d$ nnoremap Bi i nnoremap Ea a nnoremap : :let @* = @: " Tabs vs. Spaces nnoremap :retab! nnoremap :setl expandtab!:set expandtab? " todo: custom function to retab only indentation " Empty Lines nnoremap :call Enter(0) nnoremap :call Enter(1) function! s:Enter(shift) if !a:shift if col(".")-1 exe "normal o\0\"_d$" else exe "normal O\0\"_d$j" end else exe "normal O\0\"_d$" endif endfunction " Markdown Stuff vnoremap * `>a*` vnoremap _ `>a__` " === GENERAL ABBREVIATIONS === cabbr rcpath fnamemodify($MYVIMRC, ":p:h") cabbr %% expand('%:p:h') digraph <3 9829 digraph ue 252 digraph UE 220 digraph ae 228 digraph AE 196 digraph oe 246 digraph OE 214 digraph ss 223 " === GENERAL AUTOCOMMANDS === nnoremap h :call toggleWUC() function! s:updateWUC() if exists("b:hlwuc") if b:hlwuc > 1 call matchdelete(b:hlwuc) end end if exists("b:word_hl") let hl = b:word_hl else let hl = "Underlined" endif let str = "\\<".escape(expand(""), "\\")."\\>" let b:hlwuc = matchadd(hl, str) "echom str endfunc function! s:toggleWUC() augroup hlwuc if exists("b:hlwuc") autocmd! if b:hlwuc > 1 call matchdelete(b:hlwuc) end unlet b:hlwuc else call updateWUC() autocmd CursorMoved call updateWUC() autocmd CursorMovedI call updateWUC() endif augroup END endfunction function! Autosave() if &autowriteall==1 silent w echo "Lost focus, buffer saved." redraw endif endfunction au FocusLost * call Autosave() au WinLeave * call Autosave() vnoremap g :call GrepOperator(visualmode()) nnoremap g :set operatorfunc=GrepOperatorg@ function! s:GrepOperator(type) let reg1 = @@ if a:type==# 'v' execute "normal! `y" elseif a:type==# 'char' execute "normal! `[y`]" else return end echom "vimgrep! /\\M".escape(@@, "\\")."/ *" silent! execute "vimgrep /\\M".escape(@@, "\\")."/j *" let @@ = reg1 copen set nowrap endfunction " Window Height stuff function! SetWinMinHeight(num) execute "set winminheight=".0 execute "set winheight=".(a:num+1) execute "set winminheight=".a:num execute "set winheight=".9999 endfunc call SetWinMinHeight(2) function! AddWinMinHeight(num) let a:new = &winminheight + a:num call SetWinMinHeight(a:new) set winminheight? endfunc nnoremap = :call AddWinMinHeight(1) nnoremap - :call AddWinMinHeight(-1) if has("autocmd") " Enable file type detection. " Use the default filetype settings, so that mail gets 'tw' set to 72, " 'cindent' is on in C files, etc. " Also load indent files, to automatically do language-dependent indenting. filetype plugin indent on " Put these in an autocmd group, so that we can delete them easily. augroup vimrcEx au! " For all text files set 'textwidth' to 78 characters. autocmd FileType text setlocal textwidth=78 " When editing a file, always jump to the last known cursor position. " Don't do it when the position is invalid or when inside an event handler " (happens when dropping a file on gvim). autocmd BufReadPost * \ if line("'\"") >= 1 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif augroup END endif " === FILETYPE SPECIFIC STUFF === " Vimscript Stuff au BufNewFile,BufRead *.vim,*vimrc :nnoremap :so % au BufNewFile,BufRead *.vim,*vimrc :nnoremap c A" au BufNewFile,BufRead *.vim,*vimrc :nnoremap if ofunction! m'()endfunction`'l " --- C / C++ Stuff --- " Insert Stuff au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap ii o#include <>i au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap ip oprintf("m'\n");`'a au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap im oint main(int argc, char *args[]) {}O " Other Stuff au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap ; m'$a;`' " --- Ruby Stuff --- " Insert Stuff au BufNewFile,BufRead *.rb :nnoremap ic oclass m'end`'a au BufNewFile,BufRead *.rb :nnoremap id odef m'()end`'a " Other Stuff au BufNewFile,BufRead *.rb setl expandtab au BufNewFile,BufRead *.rb nnoremap :w:!ruby % au BufNewFile,BufRead *.rb nnoremap :w:!ruby -wc % au BufNewFile,BufRead *.rb :nnoremap C :call RubyComment(0) au BufNewFile,BufRead *.rb :nnoremap c :call RubyComment(1) au BufNewFile,BufRead *.rb :vnoremap C :call RubyComment(0) au BufNewFile,BufRead *.rb :vnoremap c :call RubyComment(1) function! s:RubyComment(a) if a:a==0 silent! exec '.s/\m^\s*\zs#*//' elseif a:a==1 silent! exec '.s/\v^(\s*#)@!/#/' end endfunction augroup rbindent autocmd! au BufNewFile,BufRead *.rb :set noexpandtab au BufNewFile,BufRead *.rb :retab! au BufWritePre *.rb :set expandtab au BufWritePre *.rb :set tabstop=2 " TODO: find a way to change it back to whatever it was before au BufWritePre *.rb :retab au BufWritepost *.rb :set noexpandtab au BufWritepost *.rb :retab! augroup END