-
-
Save slmingol/3049502 to your computer and use it in GitHub Desktop.
My .vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scriptencoding utf-8 | |
set encoding=utf-8 | |
set nocompatible | |
""""""""""""""" SETUP VUNDLER """"""""""""""""""""""" | |
if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.vim")) | |
"(only if it's correctly installed) | |
filetype off | |
set rtp+=~/.vim/bundle/vundle/ | |
:silent! call vundle#rc() | |
Bundle 'gmarik/vundle' | |
"Required util library | |
Bundle 'L9' | |
"Displays a file system tree (currently mapped to F6) | |
Bundle "The-NERD-tree" | |
"Auto alignment script | |
"usage: select text and type ":Align =<Enter>" | |
"to align along the = character | |
Bundle "Align" | |
"Use ctrl-a/ctrl-x to swap values like "true" -> "false" | |
Bundle "mjbrownie/swapit" | |
"Automatic html/xml tag closing with ctrl-<space> | |
Bundle "closetag.vim" | |
"Handle surroundings (ex.: type viwS<div> to surround current word with a div | |
Bundle "tpope/vim-surround.git" | |
"use :A to switch between header and implementation file | |
Bundle "a.vim" | |
"lots of color schemes | |
Bundle "flazz/vim-colorschemes.git" | |
"Improves the % key (find matching paranthesis) to handle html tags. | |
Bundle "tsaleh/vim-matchit.git" | |
"Quickly find files in current directory subtree | |
Bundle "FuzzyFinder" | |
"Powerful html coding plugin | |
Bundle "mattn/zencoding-vim" | |
"markdown support and syntax highlighting | |
Bundle "tpope/vim-markdown.git" | |
"HTML5 and CSS3 syntax and completion | |
Bundle "othree/html5.vim" | |
Bundle "css3" | |
"coffee script support | |
Bundle "kchmck/vim-coffee-script" | |
"helper functions for blogging with jekyll | |
Bundle "csexton/jekyll.vim" | |
endif | |
"""""""""""""""""" SET VARIABLES """"""""""""""""""""""""""""""""" | |
let g:is_posix = 1 | |
let mapleader = "," | |
let maplocalleader = "," | |
let g:use_zen_leader_key = '<c-l>' | |
let g:user_zen_leader_key = '<c-l>' | |
let g:use_zen_complete_tag = 1 | |
let g:xml_syntax_folding = 1 | |
let g:closetag_html_style = 1 | |
let g:indent_guides_guide_size = 1 | |
set history=256 " Number of things to remember in history. | |
set timeoutlen=500 " Time to wait after ESC (default causes an annoying delay) | |
set modeline | |
set modelines=5 " default numbers of lines to read for modeline instructions | |
set autowrite " Writes on make/shell commands | |
set autoread | |
set backup | |
set writebackup | |
set directory=~/.vim,~/tmp,/var/tmp,/tmp | |
set backupdir=~/.vim,~/tmp,/var/tmp,/tmp | |
set hidden " The current buffer can be put to the background without writing to disk | |
set hlsearch " highlight search | |
set ignorecase | |
set smartcase " be case sensitive when input has a capital letter | |
set incsearch " show matches while typing | |
set nowrap | |
set textwidth=0 " Don't wrap lines by default | |
if exists('+colorcolumn') | |
set colorcolumn=+1 " if cc is supported and hard wrap is on, show a colored column | |
endif | |
set tabstop=2 " tab size eql 2 spaces | |
set softtabstop=2 | |
set shiftwidth=2 " default shift width for indents | |
set expandtab " replace tabs with ${tabstop} spaces | |
set smarttab | |
set backspace=indent | |
set backspace+=eol | |
set backspace+=start | |
set autoindent | |
set cindent | |
set indentkeys-=0# " do not break indent on # | |
set cinkeys-=0# | |
set cinoptions=:s,ps,ts,cs | |
set cinwords=if,else,while,do | |
set cinwords+=for,switch,case | |
set number " line numbers | |
set showmatch " Show matching brackets. | |
set matchtime=2 " Bracket blinking. | |
set wildmode=longest,list " At command line, complete longest common string, then list alternatives. | |
set novisualbell " No blinking | |
set noerrorbells " No noise. | |
set vb t_vb= " disable any beeps or flashes on error | |
set laststatus=2 " always show status line. | |
set shortmess=atI " shortens messages | |
set showcmd " display an incomplete command in statusline | |
set statusline=%<%f\ | |
set stl+=[%{&ff}] | |
set stl+=[%{&fenc==\"\"?&enc:&fenc}] | |
set stl+=%{((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\")} | |
set stl+=%y%m%r%= | |
set stl+=%-14.(%l,%c%V%)\ %P | |
set foldenable " Turn on folding | |
set foldmethod=syntax | |
set foldopen=block,hor,tag " what movements open folds | |
set foldopen+=percent,mark | |
set foldopen+=quickfix | |
set foldlevel=100 "Don't autofold | |
set splitright | |
set list " display unprintable characters (F4 toggles) | |
set listchars=tab:▸\ ,eol:¬,trail:·,extends:»,precedes:« | |
:silent! set completeopt=longest,menu,preview " | |
""""""""""""""""""" SPECIFIC FILE HANDLING """""""""""""""""""" | |
"Handle scss files like css files | |
au BufRead,BufNewFile *.scss set filetype=css | |
"auto find git base path | |
autocmd BufNewFile,BufRead let git_base_path = substitute(system("git rev-parse --show-toplevel"), '\n', '', '') | |
""""""""""""" CUSTOM COMMANDS """"""""""""""""""""" | |
"enable writing as root | |
command W execute 'w !sudo tee % >/dev/null' | e! % | |
"force quit command | |
command Q qa! | |
"command for replacing stupid windows endings | |
command UnixEndings %s/ | |
//g | |
"use ruby to inflate/deflate current selection | |
command -range Deflate :'<,'>!ruby -rzlib -e "puts Zlib::Deflate.deflate(ARGF.read)" | |
command -range Inflate :'<,'>!ruby -rzlib -e "puts Zlib::Inflate.inflate(ARGF.read)" | |
""""""""""" CUSTOM KEY MAPPINGS """""""""""""""""" | |
"use leader-f for formatiing | |
nnoremap <leader>f gg=G | |
vnoremap <leader>f = | |
"special formatting for different file types | |
autocmd filetype xml map <leader>f gg!Gxmllint --format -<CR> | |
autocmd filetype html map <leader>f gg!Gtidy -q -i 2>/dev/null<CR> | |
autocmd filetype c map <leader>f gg!Gastyle -c -s2<CR> | |
autocmd filetype cpp map <leader>f gg!Gastyle -c -s2<CR> | |
autocmd filetype java map <leader>f gg!Gastyle --mode java -c -s2<CR> | |
autocmd filetype text map <leader>f gggqG | |
autocmd filetype markdown map <leader>f gggqG | |
"use ,j to join the whole paragraph to one line | |
nnoremap <leader>j vipJ0 | |
"use ,w to (re)wrap the current paragraph | |
nnoremap <leader>w gqip | |
"switch to hex view and back | |
nnoremap <leader>x :%!xxd<CR> | |
nnoremap <leader>X :%!xxd -r<CR> | |
vnoremap <leader>x :!xxd<CR> | |
vnoremap <leader>X :!xxd -r<CR> | |
"spell checker | |
map <leader>s :w!<cr>:!aspell -c %<cr>:e! %<cr> | |
"use ,, to cycle between last and current buffer | |
nnoremap <leader><leader> <c-^> | |
"Select last pasted text | |
nnoremap <leader>v V`] | |
"Use tab to switch between windows | |
nnoremap <TAB> <C-w>w | |
"split lines from normal mode | |
nnoremap <C-J> a<CR><Esc>k$ | |
"Insert newline from command mode by using Enter | |
nnoremap <silent> <CR> o<Esc>d$ | |
"Open FuzzyFinder for files with ,o (for open) | |
nnoremap <silent> <leader>o :FufFile<CR> | |
"Open FuzzyFinder for lines with ,l (for line) | |
nnoremap <silent> <leader>l :FufLine<CR> | |
"shortcuts to align selection using the align plugin | |
vnoremap <silent> <leader><bar> :Align <bar><CR> | |
vnoremap <silent> <leader>, :Align ,<CR> | |
vnoremap <silent> <leader>- :Align -<CR> | |
vnoremap <silent> <leader>= :Align =<CR> | |
vnoremap <silent> <leader>" :Align "<CR> | |
"use ctrl-space to trigger intelligent (omnifunc) auto-completion | |
"where possible and word completion in other cases | |
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ? | |
\ "\<lt>C-n>" : | |
\ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" . | |
\ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" . | |
\ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>" | |
imap <C-@> <C-Space> | |
"fix home/end keys (in some terminals) | |
map OH <Home> | |
map OF <End> | |
imap OH <Home> | |
imap OF <End> | |
cmap OH <Home> | |
cmap OF <End> | |
"...and make them smart: | |
"first press goes to first/last visible char, second one to beginning/end of line | |
noremap <expr> <Home> (col('.') == matchend(getline('.'), '^\s*')+1 ? '0' : '^') | |
noremap <expr> <End> (col('.') == match(getline('.'), '\s*$') ? '$' : 'g_') | |
vnoremap <expr> <End> (col('.') == match(getline('.'), '\s*$') ? '$h' : 'g_') | |
imap <Home> <C-o><Home> | |
imap <End> <C-o><End> | |
""""""""""""""" FUNCTION KEYS """"""""""""""""""""""""""" | |
"toggle paste mode | |
set pastetoggle=<f2> | |
nnoremap <silent> <f2> :set invpaste paste?<cr> | |
inoremap <silent> <f2> <C-\><C-O>:set invpaste paste?<cr> | |
"toggle line number display | |
nnoremap <silent> <f3> :set invnumber<cr> | |
inoremap <silent> <f3> <C-\><C-O>:set invnumber<cr> | |
"toggle display of invisible characters | |
nnoremap <silent> <f4> :set invlist<cr> | |
inoremap <silent> <f4> <C-\><C-O>:set invlist<cr> | |
"toggle word wrapping | |
nnoremap <silent> <f5> :set invwrap wrap?<cr> | |
nnoremap <c-f5> :call ToggleTextWidth()<cr> | |
"in insert mode, toggle auto hard-wrap | |
inoremap <silent> <f5> <esc> :call ToggleTextWidth()<cr>i | |
inoremap <silent> <c-f5> <C-\><C-O> :call ToggleTextWidth()<cr> | |
"toggle NERD tree tab | |
nnoremap <silent> <f6> :NERDTreeToggle<cr> | |
"in insert mode, insert current file name | |
inoremap <silent> <f6> <C-R>=expand("%:p")<cr> | |
"previous buffer | |
nnoremap <silent> <f7> :bprev<cr> | |
"previous paragraph in insert mode | |
inoremap <silent> <f7> <esc>{i | |
"next buffer | |
nnoremap <silent> <f8> :bnext<cr> | |
"next paragraph in insert mode | |
inoremap <silent> <f8> <esc>}i | |
"close current buffer without closing tab | |
nnoremap <silent> <f9> :bprevious<CR>:bdelete #<CR> | |
inoremap <silent> <f9> <C-\><C-O>:bprevious<CR>:bdelete #<CR> | |
"hard shutdown (closes all buffers even if unsaved) | |
nnoremap <silent> <f10> :qa!<cr> | |
inoremap <silent> <f10> <C-\><C-O>:qa!<cr> | |
"toggle automatic tab expansion to spaces | |
nnoremap <silent> <f12> :set invexpandtab expandtab?<cr> | |
inoremap <silent> <f12> <C-\><C-O>:set invexpandtab expandtab?<cr> | |
""""""""""""""""" SYNTAX HIGHLIGHTING AND COLORS """""""""""""""" | |
filetype plugin indent on " Automatically detect file types. | |
syntax enable | |
set t_Co=256 | |
"try different colorschemes (inverse order of preference) | |
set background=dark | |
:silent! colorscheme slate | |
:silent! colorscheme zenburn | |
""""""""""""""""""""""""" GUI STUFF """"""""""""""""""""""" | |
if has('gui_running') | |
" set guioptions=cMg " console dialogs, do not show menu and toolbar | |
if has('mac') | |
set guifont=Andale\ Mono:h13 | |
set fuoptions=maxvert,maxhorz ",background:#00AAaaaa | |
endif | |
"set background=light | |
":silent! colorscheme solarized | |
vnoremap <C-Del> "+x | |
vnoremap <C-Insert> "+y | |
map <S-Insert> "+gP | |
cmap <S-Insert> <C-R>+ | |
imap <S-Insert> <C-R>+ | |
nnoremap <silent> <F11> :call ToggleWindowSize(0)<CR> | |
imap <silent> <F11> <C-O><F11> | |
endif | |
"""""""""""""" FUNCTIONS """""""""""""""""""""" | |
function ToggleTextWidth() | |
if &tw | |
let s:save_tw = &tw | |
set tw=0 | |
echo "Hard wrap off" | |
else | |
if exists("s:save_tw") | |
let &tw = s:save_tw | |
unlet s:save_tw | |
else | |
" default value if 'tw' is zero the first time | |
set tw=73 | |
endif | |
echo "Hard wrap on" | |
endif | |
endfunction | |
function ToggleWindowSize(act) | |
if a:act < 0 || a:act > 2 | return | endif | |
let posX = getwinposx() | |
let posY = getwinposy() | |
let actTab = "XXX__X_XR__XX_X__RRRR__R" | |
let idx = ((exists("g:twsWM") + exists("g:twsHM") * 2) * 3 + a:act) * 2 | |
let actW = strpart(actTab, idx, 1) | |
let actH = strpart(actTab, idx + 1, 1) | |
" note. g:tws + [Width,Height,X,Y] + [Maximized,Saved] | |
if actW == "X" | |
let g:twsWS = &columns | let g:twsXS = posX | |
set columns=999 | |
let posX = getwinposx() | |
let g:twsWM = &columns | let g:twsXM = posX | |
elseif actW == "R" | |
if g:twsWM == &columns | |
let &columns = g:twsWS | |
if g:twsXM == posX | let posX = g:twsXS | endif | |
endif | |
unlet g:twsWM g:twsWS g:twsXM g:twsXS | |
endif | |
if actH == "X" | |
let g:twsHS = &lines | let g:twsYS = posY | |
set lines=999 | |
let posY = getwinposy() | |
let g:twsHM = &lines | let g:twsYM = posY | |
elseif actH == "R" | |
if g:twsHM == &lines | |
let &lines = g:twsHS | |
if g:twsYM == posY | let posY = g:twsYS | endif | |
endif | |
unlet g:twsHM g:twsHS g:twsYM g:twsYS | |
endif | |
execute "winpos " . posX . " " . posY | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment