Skip to content

Instantly share code, notes, and snippets.

@planbnet
Last active September 28, 2015 10:09
Show Gist options
  • Select an option

  • Save planbnet/1422486 to your computer and use it in GitHub Desktop.

Select an option

Save planbnet/1422486 to your computer and use it in GitHub Desktop.

Revisions

  1. planbnet revised this gist Apr 11, 2014. 1 changed file with 22 additions and 3 deletions.
    25 changes: 22 additions & 3 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -44,14 +44,16 @@ if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.vim"))
    Bundle "msanders/snipmate.vim"
    "syntax checking
    Bundle 'scrooloose/syntastic'
    "undo tree
    Bundle "sjl/gundo.vim.git"

    """""""""""""""""""""""""""""""""""""""Language specific plugins
    "Powerful html coding plugin
    "ex.: select multiple lines and do ctrl-z ul>li*
    "ex.: type div>p#foo$*3>a and hit CTRL-Z
    Bundle "mattn/zencoding-vim"
    "markdown support and syntax highlighting
    Bundle "tpope/vim-markdown.git"
    Bundle "plasticboy/vim-markdown.git"
    "HTML5 and CSS3 syntax and completion
    Bundle "othree/html5.vim"
    Bundle "css3"
    @@ -156,7 +158,7 @@ set foldlevel=100 "Don't autofold

    set splitright

    set list " display unprintable characters (F4 toggles)
    set nolist "do not display unprintable characters (F4 toggles)
    set listchars=tab:▸\ ,eol:¬,trail:·,extends:»,precedes:«

    :silent! set completeopt=longest,menu,preview "
    @@ -184,7 +186,7 @@ command W execute 'w !sudo tee % >/dev/null' | e! %
    command Q qa!

    "command for replacing stupid windows endings
    command UnixEndings %s/^M//g
    command UnixEndings set ff=unix

    "use ruby to inflate/deflate current selection
    command -range Deflate :'<,'>!ruby -rzlib -e "puts Zlib::Deflate.deflate(ARGF.read)"
    @@ -312,6 +314,9 @@ inoremap <silent> <c-f5> <C-\><C-O> :call ToggleTextWidth()<cr>
    nnoremap <silent> <f6> :NERDTreeToggle<cr>
    "in insert mode, insert current file name
    inoremap <silent> <f6> <C-R>=expand("%:p")<cr>
    "toggle undo tree on ctrl F6
    nnoremap <silent> <C-f6> :GundoToggle<cr>
    inoremap <silent> <C-f6> <C-\><C-O> :GundoToggle<cr>
    "previous buffer
    nnoremap <silent> <f7> :bprev<cr>
    @@ -330,6 +335,8 @@ nnoremap <silent> <c-f8> :CtrlPMRUFiles<cr>
    "close current buffer without closing tab
    nnoremap <silent> <f9> :bprevious<CR>:bdelete #<CR>
    inoremap <silent> <f9> <C-\><C-O>:bprevious<CR>:bdelete #<CR>
    nnoremap <silent> <C-f9> :q!<CR>
    inoremap <silent> <C-f9> <C-\><C-O>:q!<CR>
    "hard shutdown (closes all buffers even if unsaved)
    nnoremap <silent> <f10> :qa!<cr>
    @@ -377,6 +384,18 @@ endif


    """""""""""""" FUNCTIONS """"""""""""""""""""""
    command! -nargs=* Make write | let g:make_args="<args>" | make <args> | cwindow 6
    function! Make2()
    if !exists("g:make_args")
    let g:make_args = ""
    endif
    wall
    exec "make " . g:make_args
    cwindow 6
    redraw
    endfunction
    inoremap <C-B> <ESC>:call Make2()<CR><C-L>
    noremap <C-B> :call Make2()<CR><C-L>
    function ToggleTextWidth()
    if &tw
  2. planbnet revised this gist Mar 25, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,7 @@ if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.vim"))
    "to align along the = character
    Bundle "Align"
    "Alternate file plugin with objc support
    "use :A to switch between header and implementation file
    Bundle "nacitar/a.vim"
    "Use ctrl-a/ctrl-x to swap values like "true" -> "false"
    Bundle "mjbrownie/swapit"
    @@ -35,8 +36,6 @@ if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.vim"))
    Bundle "tpope/vim-repeat.git"
    "git integration
    Bundle "tpope/vim-fugitive"
    "use :A to switch between header and implementation file
    "Bundle ''
    "Improves the % key (find matching paranthesis) to handle html tags.
    Bundle 'tsaleh/vim-matchit.git'
    "File finder (CTRL-P)
  3. planbnet revised this gist Mar 25, 2014. 1 changed file with 40 additions and 8 deletions.
    48 changes: 40 additions & 8 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,8 @@ if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.vim"))
    "usage: select text and type ":Align =<Enter>"
    "to align along the = character
    Bundle "Align"
    "Alternate file plugin with objc support
    Bundle "nacitar/a.vim"
    "Use ctrl-a/ctrl-x to swap values like "true" -> "false"
    Bundle "mjbrownie/swapit"
    "Automatic html/xml tag closing with ctrl-<space>
    @@ -31,14 +33,18 @@ if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.vim"))
    """ysiw' insert ' (my shortcut: +')
    Bundle "tpope/vim-surround.git"
    Bundle "tpope/vim-repeat.git"
    "git integration
    Bundle "tpope/vim-fugitive"
    "use :A to switch between header and implementation file
    Bundle 'a.vim'
    "Bundle ''
    "Improves the % key (find matching paranthesis) to handle html tags.
    Bundle 'tsaleh/vim-matchit.git'
    "File finder (CTRL-P)
    Bundle "kien/ctrlp.vim.git"
    " Snippets (use tab to expand)
    Bundle "msanders/snipmate.vim"
    "syntax checking
    Bundle 'scrooloose/syntastic'

    """""""""""""""""""""""""""""""""""""""Language specific plugins
    "Powerful html coding plugin
    @@ -50,9 +56,6 @@ if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.vim"))
    "HTML5 and CSS3 syntax and completion
    Bundle "othree/html5.vim"
    Bundle "css3"
    "coffee script support
    Bundle "kchmck/vim-coffee-script"

    endif

    """""""""""""""""" SET VARIABLES """""""""""""""""""""""""""""""""
    @@ -61,11 +64,14 @@ let g:is_posix = 1
    let mapleader = ","
    let maplocalleader = ","
    let g:user_zen_expandabbr_key = '<c-z>'
    "zen leader key is c-y by default, use c-y n to jump to next insert point
    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

    " Stop Syntastic checking angular html templates"
    let g:syntastic_html_checkers=[]

    set history=256 " Number of things to remember in history.
    set timeoutlen=500 " Time to wait after ESC (default causes an annoying delay)
    @@ -80,11 +86,16 @@ set backup
    set writebackup
    set directory=~/.vim/tmp,~/tmp,/var/tmp,/tmp
    set backupdir=~/.vim/tmp,~/tmp,/var/tmp,/tmp
    if version >= 730
    :if has('persistent_undo')
    set undodir=~/.vim/tmp,~/tmp,/var/tmp,/tmp
    set undofile " Enable undo after close
    endif

    " Remember last position in files
    if has("autocmd")
    au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
    endif

    set hidden " The current buffer can be put to the background without writing to disk

    set hlsearch " highlight search
    @@ -155,10 +166,14 @@ set scrolloff=4 "Start scrolling when we're 4 lines away from margins
    set sidescrolloff=15
    set sidescroll=1

    "config for Ctrl-p extension"
    set wildignore+=*eclipse*,*/tmp/*,*/target/*,*/node_modules/*,*.jar,*.zip,*.so,*.swp,*.class

    """"""""""""""""""" SPECIFIC FILE HANDLING """"""""""""""""""""

    "Handle scss files like css files
    au BufRead,BufNewFile *.scss set filetype=css
    au BufRead,BufNewFile *.less set filetype=css

    "auto find git base path
    autocmd BufNewFile,BufRead let git_base_path = substitute(system("git rev-parse --show-toplevel"), '\n', '', '')
    @@ -176,6 +191,9 @@ command UnixEndings %s/^M//g
    command -range Deflate :'<,'>!ruby -rzlib -e "puts Zlib::Deflate.deflate(ARGF.read)"
    command -range Inflate :'<,'>!ruby -rzlib -e "puts Zlib::Inflate.inflate(ARGF.read)"

    "Converts a httpd group to a svn auth group
    command SVNGroup norm!^Wdt i = <CR><ESC>:call setline('.',join(sort(split(substitute(getline('.'), ',', '', 'g'))), ', '))<CR>kJ

    """"""""""" CUSTOM KEY MAPPINGS """"""""""""""""""

    "use leader-f for formatiing
    @@ -189,13 +207,16 @@ 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
    autocmd filetype javascript set omnifunc=javascriptcomplete#CompleteJS

    "indent 2 for html
    autocmd FileType html setlocal ts=2 sts=2 sw=2

    "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
    "shortcuts for the vim sourrund plugin
    nmap + ysiW
    nmap - ds
    @@ -246,6 +267,11 @@ imap OF <End>
    cmap OH <Home>
    cmap OF <End>
    " Allow Ctrl-S for saving
    noremap <C-S> :update<CR>
    vnoremap <C-S> <C-C>:update<CR>
    inoremap <C-S> <C-C>:update<CR>
    "...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' : '^')
    @@ -258,7 +284,7 @@ imap <End> <C-o><End>
    "leave insert mode when pressing jk
    imap jk <Esc>
    "deleting to beginning of line in insert mode
    "deleting a line in insert mode
    imap <C-d> <Esc>d^xi
    """"""""""""""" FUNCTION KEYS """""""""""""""""""""""""""
    @@ -292,11 +318,15 @@ inoremap <silent> <f6> <C-R>=expand("%:p")<cr>
    nnoremap <silent> <f7> :bprev<cr>
    "previous paragraph in insert mode
    inoremap <silent> <f7> <esc>{i
    "ctrl p plugin: show all open buffers
    nnoremap <silent> <c-f7> :CtrlPBuffer<cr>
    "next buffer
    nnoremap <silent> <f8> :bnext<cr>
    "next paragraph in insert mode
    inoremap <silent> <f8> <esc>}i
    "ctrl p plugin: show recently used files
    nnoremap <silent> <c-f8> :CtrlPMRUFiles<cr>
    "close current buffer without closing tab
    nnoremap <silent> <f9> :bprevious<CR>:bdelete #<CR>
    @@ -320,6 +350,7 @@ set t_Co=256
    set background=dark
    :silent! colorscheme slate
    :silent! colorscheme zenburn
    hi Normal ctermbg=NONE

    """"""""""""""""""""""""" GUI STUFF """""""""""""""""""""""

    @@ -399,4 +430,5 @@ function ToggleWindowSize(act)
    unlet g:twsHM g:twsHS g:twsYM g:twsYS
    endif
    execute "winpos " . posX . " " . posY
    endfunction
    endfunction

  4. planbnet revised this gist Sep 7, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion .vimrc
    Original file line number Diff line number Diff line change
    @@ -259,7 +259,7 @@ imap <End> <C-o><End>
    imap jk <Esc>
    "deleting to beginning of line in insert mode
    imap <C-d> <C-o>xd^
    imap <C-d> <Esc>d^xi
    """"""""""""""" FUNCTION KEYS """""""""""""""""""""""""""

  5. planbnet revised this gist Sep 7, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -258,8 +258,8 @@ imap <End> <C-o><End>
    "leave insert mode when pressing jk
    imap jk <Esc>
    "deleting a word in insert mode
    imap <C-d> <C-o>diw
    "deleting to beginning of line in insert mode
    imap <C-d> <C-o>xd^
    """"""""""""""" FUNCTION KEYS """""""""""""""""""""""""""

  6. planbnet revised this gist Sep 7, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -195,6 +195,7 @@ nnoremap <leader>j vipJ0
    "use ,w to (re)wrap the current paragraph
    nnoremap <leader>w gqip
    "shortcuts for the vim sourrund plugin
    nmap + ysiW
    nmap - ds
  7. planbnet revised this gist Sep 7, 2012. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -257,6 +257,9 @@ imap <End> <C-o><End>
    "leave insert mode when pressing jk
    imap jk <Esc>
    "deleting a word in insert mode
    imap <C-d> <C-o>diw
    """"""""""""""" FUNCTION KEYS """""""""""""""""""""""""""

    "toggle paste mode
  8. planbnet revised this gist Sep 6, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion .vimrc
    Original file line number Diff line number Diff line change
    @@ -80,8 +80,10 @@ set backup
    set writebackup
    set directory=~/.vim/tmp,~/tmp,/var/tmp,/tmp
    set backupdir=~/.vim/tmp,~/tmp,/var/tmp,/tmp
    if version >= 730
    set undodir=~/.vim/tmp,~/tmp,/var/tmp,/tmp
    set undofile " Enable undo after close
    endif

    set hidden " The current buffer can be put to the background without writing to disk

    @@ -393,4 +395,4 @@ function ToggleWindowSize(act)
    unlet g:twsHM g:twsHS g:twsYM g:twsYS
    endif
    execute "winpos " . posX . " " . posY
    endfunction
    endfunction
  9. planbnet revised this gist Sep 6, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -242,6 +242,7 @@ 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' : '^')
  10. planbnet revised this gist Sep 6, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -168,8 +168,7 @@ command W execute 'w !sudo tee % >/dev/null' | e! %
    command Q qa!

    "command for replacing stupid windows endings
    command UnixEndings %s/
    //g
    command UnixEndings %s/^M//g

    "use ruby to inflate/deflate current selection
    command -range Deflate :'<,'>!ruby -rzlib -e "puts Zlib::Deflate.deflate(ARGF.read)"
  11. planbnet revised this gist Sep 6, 2012. 1 changed file with 39 additions and 19 deletions.
    58 changes: 39 additions & 19 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.vim"))
    :silent! call vundle#rc()
    Bundle 'gmarik/vundle'

    "lots of color schemes
    Bundle 'flazz/vim-colorschemes.git'
    "Required util library
    Bundle 'L9'
    "Displays a file system tree (currently mapped to F6)
    @@ -22,17 +24,26 @@ if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.vim"))
    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
    "Handle surroundings
    """viwS<div> to surround current word with a div
    """ds' delete surrounding ' (my shortcut: -')
    """cs([ change ( to [
    """ysiw' insert ' (my shortcut: +')
    Bundle "tpope/vim-surround.git"
    Bundle "tpope/vim-repeat.git"
    "use :A to switch between header and implementation file
    Bundle "a.vim"
    "lots of color schemes
    Bundle "flazz/vim-colorschemes.git"
    Bundle 'a.vim'
    "Improves the % key (find matching paranthesis) to handle html tags.
    Bundle "tsaleh/vim-matchit.git"
    "Quickly find files in current directory subtree
    Bundle "FuzzyFinder"
    Bundle 'tsaleh/vim-matchit.git'
    "File finder (CTRL-P)
    Bundle "kien/ctrlp.vim.git"
    " Snippets (use tab to expand)
    Bundle "msanders/snipmate.vim"

    """""""""""""""""""""""""""""""""""""""Language specific plugins
    "Powerful html coding plugin
    "ex.: select multiple lines and do ctrl-z ul>li*
    "ex.: type div>p#foo$*3>a and hit CTRL-Z
    Bundle "mattn/zencoding-vim"
    "markdown support and syntax highlighting
    Bundle "tpope/vim-markdown.git"
    @@ -41,17 +52,15 @@ if (filereadable($HOME."/.vim/bundle/vundle/autoload/vundle.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:user_zen_expandabbr_key = '<c-z>'
    let g:use_zen_complete_tag = 1
    let g:xml_syntax_folding = 1
    let g:closetag_html_style = 1
    @@ -69,15 +78,18 @@ set autoread

    set backup
    set writebackup
    set directory=~/.vim,~/tmp,/var/tmp,/tmp
    set backupdir=~/.vim,~/tmp,/var/tmp,/tmp
    set directory=~/.vim/tmp,~/tmp,/var/tmp,/tmp
    set backupdir=~/.vim/tmp,~/tmp,/var/tmp,/tmp
    set undodir=~/.vim/tmp,~/tmp,/var/tmp,/tmp
    set undofile " Enable undo after close

    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 magic " sensible regexp special char handling

    set nowrap
    set textwidth=0 " Don't wrap lines by default
    @@ -137,6 +149,10 @@ set listchars=tab:▸\ ,eol:¬,trail:·,extends:»,precedes:«

    :silent! set completeopt=longest,menu,preview "

    set scrolloff=4 "Start scrolling when we're 4 lines away from margins
    set sidescrolloff=15
    set sidescroll=1

    """"""""""""""""""" SPECIFIC FILE HANDLING """"""""""""""""""""

    "Handle scss files like css files
    @@ -178,6 +194,9 @@ nnoremap <leader>j vipJ0
    "use ,w to (re)wrap the current paragraph
    nnoremap <leader>w gqip
    nmap + ysiW
    nmap - ds
    "switch to hex view and back
    nnoremap <leader>x :%!xxd<CR>
    nnoremap <leader>X :%!xxd -r<CR>
    @@ -201,11 +220,6 @@ 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>
    @@ -233,10 +247,14 @@ cmap OF <End>
    "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> <Home> (col('.') == matchend(getline('.'), '^\s*')+1 ? '0' : '^')
    vnoremap <expr> <End> (col('.') == match(getline('.'), '\s*$') ? '$h' : 'g_')
    imap <Home> <C-o><Home>
    imap <End> <C-o><End>
    "leave insert mode when pressing jk
    imap jk <Esc>
    """"""""""""""" FUNCTION KEYS """""""""""""""""""""""""""

    "toggle paste mode
    @@ -304,6 +322,8 @@ if has('gui_running')
    if has('mac')
    set guifont=Andale\ Mono:h13
    set fuoptions=maxvert,maxhorz ",background:#00AAaaaa
    else
    set guifont=Consolas:h11
    endif

    "set background=light
    @@ -373,4 +393,4 @@ function ToggleWindowSize(act)
    unlet g:twsHM g:twsHS g:twsYM g:twsYS
    endif
    execute "winpos " . posX . " " . posY
    endfunction
    endfunction
  12. planbnet revised this gist Jan 19, 2012. 1 changed file with 30 additions and 6 deletions.
    36 changes: 30 additions & 6 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -59,16 +59,18 @@ let g:indent_guides_guide_size = 1


    set history=256 " Number of things to remember in history.
    set timeoutlen=250 " Time to wait after ESC (default causes an annoying delay)
    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 nobackup
    set nowritebackup
    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

    @@ -79,6 +81,9 @@ 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
    @@ -137,10 +142,12 @@ set listchars=tab:▸\ ,eol:¬,trail:·,extends:»,precedes:«
    "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 w !sudo tee % > /dev/null
    command W execute 'w !sudo tee % >/dev/null' | e! %
    "force quit command
    command Q qa!

    @@ -180,6 +187,12 @@ 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
    @@ -193,6 +206,13 @@ 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 == '' ?
    @@ -234,8 +254,10 @@ 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> <C-\><C-O>:call ToggleTextWidth()<cr>
    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>
    @@ -304,6 +326,7 @@ 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
    @@ -312,6 +335,7 @@ function ToggleTextWidth()
    " default value if 'tw' is zero the first time
    set tw=73
    endif
    echo "Hard wrap on"
    endif
    endfunction

    @@ -349,4 +373,4 @@ function ToggleWindowSize(act)
    unlet g:twsHM g:twsHS g:twsYM g:twsYS
    endif
    execute "winpos " . posX . " " . posY
    endfunction
    endfunction
  13. planbnet created this gist Dec 2, 2011.
    352 changes: 352 additions & 0 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,352 @@
    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=250 " 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 nobackup
    set nowritebackup

    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

    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

    """"""""""""" CUSTOM COMMANDS """""""""""""""""""""

    "enable writing as root
    command W w !sudo tee % > /dev/null
    "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 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>
    "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>
    "in insert mode, toggle auto hard-wrap
    inoremap <silent> <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
    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
    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