Skip to content

Instantly share code, notes, and snippets.

@rossipedia
Created July 13, 2015 04:15
Show Gist options
  • Save rossipedia/ac9db0a5674388b1a719 to your computer and use it in GitHub Desktop.
Save rossipedia/ac9db0a5674388b1a719 to your computer and use it in GitHub Desktop.
.vimrc
"
" Who wants compatible? Yuck...
"
set nocompatible
"
" NeoBundle
"
if has('win32') || has('win64')
set runtimepath+=~/vimfiles/bundle/neobundle.vim/
else
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
call neobundle#begin(expand('~/.neobundle/'))
NeoBundleFetch 'Shougo/neobundle.vim'
" Airline
NeoBundle 'bling/vim-airline'
" Bundles
" NeoBundle 'Shougo/vimproc.vim'
NeoBundle 'tpope/vim-fugitive'
NeoBundle 'vim-scripts/matchit.zip'
NeoBundle 'ervandew/supertab'
NeoBundle 'vim-scripts/sudo.vim'
NeoBundle 'tpope/vim-ragtag'
NeoBundle 'groenewege/vim-less'
NeoBundle 'tpope/vim-surround'
NeoBundle 'rossipedia/vim-coffee-script'
NeoBundle 'tpope/vim-markdown'
NeoBundle 'PProvost/vim-ps1'
" NeoBundle 'OrangeT/vim-csharp'
NeoBundle 'tomtom/tlib_vim'
" NeoBundle 'Shougo/unite.vim'
NeoBundle 'cespare/vim-toml'
NeoBundle 'digitaltoad/vim-jade'
NeoBundle 'tpope/vim-repeat'
NeoBundle 'mattn/emmet-vim'
NeoBundle 'scrooloose/nerdcommenter'
NeoBundle 'godlygeek/tabular'
NeoBundle 'dhruvasagar/vim-table-mode'
NeoBundle 'fatih/vim-go'
NeoBundle 'rust-lang/rust.vim'
NeoBundle 'xuhdev/SingleCompile'
NeoBundle 'JulesWang/css.vim'
" Html 5
NeoBundle 'othree/html5.vim'
" Javascript
NeoBundle 'jelera/vim-javascript-syntax'
NeoBundle 'lukaszb/vim-web-indent'
NeoBundle 'pangloss/vim-javascript'
NeoBundle 'elzr/vim-json'
NeoBundle '29decibel/codeschool-vim-theme'
NeoBundle 'twerth/ir_black'
NeoBundle 'ekalinin/Dockerfile.vim'
NeoBundle 'mxw/vim-jsx'
" F#
NeoBundle 'fsharp/fsharpbinding'
" Go
" NeoBundle 'fatih/vim-go'
" Folder local vim settings
NeoBundle 'thinca/vim-localrc'
"
" If we have a local .neobundle.local, source it
"
if filereadable($HOME . "/.neobundle.local")
source ~/.neobundle.local
endif
call neobundle#end()
"
" Some default settings
"
set shiftwidth=2
set tabstop=2
set smarttab
set showtabline=1
set number
if has("gui_running")
set cursorline
endif
set encoding=utf-8
set scrolloff=5
set cindent
set smartindent
set autoindent
set expandtab
set nolist
set ignorecase
set smartcase
set wildmenu
set showmode
set incsearch
set hlsearch
set virtualedit=block
set nowrap
"
" File formats yay
"
set ffs=unix,dos
if has("win32")
set ff=dos
else
set ff=unix
endif
"
" Turn off that damn eol handling
"
set noeol
"
" Highlight dos files in red in status line
"
hi User9 term=reverse cterm=bold ctermbg=12 gui=bold guibg=Red
"
" Custom Status Line
"
set laststatus=2
" set statusline=
" set statusline+=%-3.3n
" set statusline+=\[%{strlen(&ft)?&ft:'none'}]
" set statusline+=\ %F
" set statusline+=\ %9*%{&ff=='unix'?'':&ff.'\ format'}%*
" set statusline+=%#warningmsg#
" set statusline+=%{fugitive#statusline()}
" set statusline+=%*
" set statusline+=%=
" set statusline+=0x%-8B
" set statusline+=LINE\:\ %-6l\ CHAR\:\ %-6c\ COL\:\ %-6v
" set statusline+=%<%P
"
" Set height of command line, and show last cmd executed
"
set showcmd
set cmdheight=2
"
" Gah, can't stand these backup files.
"
set nobackup
set nowritebackup
set noswapfile
"
" Turn ~ into an operator (switch case)
"
set tildeop
"
" Enter key clears search
"
nnoremap <CR> :nohlsearch<CR>
"
" mapleader
"
let mapleader=","
"
" Completion Options
"
set completeopt=longest,menuone,preview
set hidden
"
" Enable filetype indenting and plugins
"
filetype indent on
filetype plugin on
syntax on
set synmaxcol=3000
"
" Run NeoBundleCheck
"
NeoBundleCheck
"
" Handle buffer switching
"
set switchbuf+=useopen
set switchbuf+=usetab
set hidden
"
" Fix Backspace
"
set backspace=indent,eol,start
"
" Map to set CWD to folder containing file being edited
"
map \lcd :lcd %:p:h<CR>
"
" Add a new line with Shift-Enter
"
nnoremap <silent><S-CR> <Esc>i<CR><Esc>
"
" Convenience mappings for running make and make clean
"
nmap <silent> \mm :wa<CR>:make<CR>
nmap <silent> \mc :wa<CR>:make clean<CR>
nmap <silent> \mt :wa<CR>:make clean<CR>
"
" Handle our gui settings
" - Font, color, size, etc...
"
if has("gui_running")
set background=dark
colorscheme ir_dark
" Gui options: hide scrolling, menubar, tabbar, etc
set guioptions=ehi
" Show only file name on tab
set guitablabel=%t
"
" Set font based on the type of gui we're using
"
if has("gui_gtk2")
if has("win32unix")
" Cygwin
set gfn=Consolas\ 11
else
" Linux, probably
set gfn=Consolas\ 10
set linespace=2
endif
elseif has("gui_win32")
" Win32/64 GVim
set gfn=Consolas:h10
set linespace=0
" Initial size
set columns=160
set lines=50
elseif has("gui_macvim")
" MacVim
set gfn=Consolas:h12
set linespace=0
else
echo "Unknown GUI system!!!!"
endif
"
" Show or hide the menu bar with Control-F11
"
nmap <silent> <C-F11> :if &guioptions=~'m' \| set guioptions-=m \| else \| set guioptions+=m \| endif<CR>
"
" Disable the visual bell
"
set vb t_vb=
else
" set t_Co=256
" if &t_Co == 256
" set background=dark
" colorscheme codeschool
" endif
endif
"
" Python Stuff
"
"
" Hide Bike Exceptions
"
let g:bike_exceptions = 0
"
" Highlight all python syntax items
"
let python_highlight_all = 1
"
" Runs the current buffer as python script, and sets the filetype of the
" buffer to be python
"
function! RunPythonBuffer()
pclose!
setlocal filetype=python
silent %y a | below new | silent put a | silent %!python -
setlocal previewwindow ro nomodifiable nomodified
winc p
endfunction
command! RunPyBuffer call RunPythonBuffer()
map \py :RunPyBuffer<cr>
"
" Buffer handling:
" Control-K goes to next buffer
" Control-J goes to previous buffer
" \ba Clears out up to 1000 buffers (probably overkill, but oh well)
" \bd Deletes the current buffer
"
nmap <silent> <C-j> :bprevious<cr>
nmap <silent> <C-k> :bnext<cr>
nmap <silent> \ba :1,1000bd!<cr>
nmap <silent> \bd :up<cr>:bd!<cr>
"
" Maps for ctrl-f (search) and ctrl-v (replace) in visual mode
"
function! GetVisual() range
let reg_save = getreg('"')
let regtype_save = getregtype('"')
let cb_save = &clipboard
set clipboard&
normal! ""gvy
let selection = escape(getreg('"'),'/\.*$^~[')
call setreg('"', reg_save, regtype_save)
let &clipboard = cb_save
return selection
endfunction
vmap <C-H> <Esc>:%s/<c-r>=GetVisual()<cr>/
vmap <C-F> <Esc>/<c-r>=GetVisual()<cr><cr>
"
" Trim Trailing spaces on save
"
function! FnTrimTrailing()
let savepos = getpos(".")
" %s/\S\zs\s\+$//g
%s/\s\+$//g
nohl
call setpos(".", savepos)
endfunction
function! FnFileTypeTrim()
if &filetype != 'mkd'
call FnTrimTrailing()
endif
endfunction
command! TrimTrailing silent! call FnFileTypeTrim()
" autocmd FileWritePre * :TrimTrailing
" autocmd FileAppendPre * :TrimTrailing
" autocmd FilterWritePre * :TrimTrailing
" autocmd BufWritePre * :TrimTrailing
"
" Show trailing spaces
"
set listchars=tab:»·,trail:·,eol:$
"
" Some customizations for ZenCoding
"
let g:user_zen_settings = {
\ 'xml' : {
\ 'extends' : 'html',
\ }
\}
"
" NERD_Commenter Defaults
"
let NERDSpaceDelims=1
"
" Use /* */ instead of // for PHP (personal preference)
"
let g:NERD_php_alt_style=1
"
" Map Control J/K to navigate command history
"
cmap <C-J> <Down>
cmap <C-K> <Up>
"
" Twiddle Case!
"
function! TwiddleCase(str)
if a:str ==# toupper(a:str)
let result = tolower(a:str)
elseif a:str ==# tolower(a:str)
let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
else
let result = toupper(a:str)
endif
return result
endfunction
vnoremap <silent> ~ ygv"=TwiddleCase(@")<CR>Pgv
function! DoReformat(l1, l2)
execute a:l1.",".a:l2."g/./normal gqq"
nohlsearch
redraw
endfunction
command! -range=% -nargs=0 Reformat call DoReformat(<line1>, <line2>)
map <silent> \r :Reformat<CR>
" Hex mode
" nnoremap <C-H> :Hexmode<CR>
" inoremap <C-H> <Esc>:Hexmode<CR>
" vnoremap <C-H> :<C-U>Hexmode<CR>
command! -bar Hexmode call ToggleHex()
function! ToggleHex()
" hex mode should be considered a read-only operation
" save values for modified and read-only for restoration later,
" and clear the read-only flag for now
let l:modified=&mod
let l:oldreadonly=&readonly
let &readonly=0
let l:oldmodifiable=&modifiable
let &modifiable=1
if !exists("b:editHex") || !b:editHex
" save old options
let b:oldft=&ft
let b:oldbin=&bin
" set new options
setlocal binary " make sure it overrides any textwidth, etc.
let &ft="xxd"
" set status
let b:editHex=1
" switch to hex editor
%!xxd
else
" restore old options
let &ft=b:oldft
if !b:oldbin
setlocal nobinary
endif
" set status
let b:editHex=0
" return to normal editing
%!xxd -r
endif
" restore values for modified and read only state
let &mod=l:modified
let &readonly=l:oldreadonly
let &modifiable=l:oldmodifiable
endfunction
" autocmds to automatically enter hex mode and handle file writes properly
if has("autocmd")
" vim -b : edit binary using xxd-format!
augroup Binary
au!
" set binary option for all binary files before reading them
au BufReadPre *.bin,*.hex setlocal binary
" if on a fresh read the buffer variable is already set, it's wrong
au BufReadPost *
\ if exists('b:editHex') && b:editHex |
\ let b:editHex = 0 |
\ endif
" convert to hex on startup for binary files automatically
au BufReadPost *
\ if &binary | Hexmode | endif
" When the text is freed, the next time the buffer is made active it will
" re-read the text and thus not match the correct mode, we will need to
" convert it again if the buffer is again loaded.
au BufUnload *
\ if getbufvar(expand("<afile>"), 'editHex') == 1 |
\ call setbufvar(expand("<afile>"), 'editHex', 0) |
\ endif
" before writing a file when editing in hex mode, convert back to non-hex
au BufWritePre *
\ if exists("b:editHex") && b:editHex && &binary |
\ let oldro=&ro | let &ro=0 |
\ let oldma=&ma | let &ma=1 |
\ silent exe "%!xxd -r" |
\ let &ma=oldma | let &ro=oldro |
\ unlet oldma | unlet oldro |
\ endif
" after writing a binary file, if we're in hex mode, restore hex mode
au BufWritePost *
\ if exists("b:editHex") && b:editHex && &binary |
\ let oldro=&ro | let &ro=0 |
\ let oldma=&ma | let &ma=1 |
\ silent exe "%!xxd" |
\ exe "set nomod" |
\ let &ma=oldma | let &ro=oldro |
\ unlet oldma | unlet oldro |
\ endif
augroup END
endif
"
" CoffeeScript two-space indentation
"
autocmd BufNewFile,BufReadPost *.coffee setl sw=2 et ts=2
"
" EJS highlighting as HTML
"
au BufNewFile,BufRead *.ejs set filetype=html
"
" Jade files
"
au BufNewFile,BufRead *.jade set list sw=2 et ts=2
"
" Unit.vim bindings
"
nnoremap <leader>f :<C-u>Unite -start-insert file<cr>
"
" Utility functions for testing
"
function! RedBar()
hi RedBar ctermfg=white ctermbg=red guibg=red
echohl RedBar
echon repeat(" ",&columns - 1)
echohl None
endfunction
function! GreenBar()
hi GreenBar ctermfg=white ctermbg=green guibg=green
echohl GreenBar
echon repeat(" ",&columns - 1)
echohl None
endfunction
"
" Tabularize mappings
"
vnoremap <leader>ts :Tabularize /^[^\s]\*\zs/<cr>
vnoremap <leader>t, :Tabularize /^[^,]\*\zs/<cr>
vnoremap <leader>t' :Tabularize /^[^']\*\zs/<cr>
vnoremap <leader>t= :Tabularize /^\(.\+=\)\?\s/l0<cr>
"
" Cucumber tables
"
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
"
" Table mode
"
let g:table_mode_corner='|'
"
" Rust compiler setup
"
autocmd BufRead,BufNewFile Cargo.toml,Cargo.lock,*.rs compiler cargo
"
" Screw that .netrwhist file
"
let g:netrw_dirhistmax=0
"
" Allow modelines
"
set modeline
set modelines=5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment