Skip to content

Instantly share code, notes, and snippets.

@kaw2k
Created May 8, 2014 21:29
Show Gist options
  • Save kaw2k/d5465ca328ded3b08009 to your computer and use it in GitHub Desktop.
Save kaw2k/d5465ca328ded3b08009 to your computer and use it in GitHub Desktop.
" ==============================================================================
" Install Bundles
" ==============================================================================
" Required for neocomplcache
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
" Installed Bundles
Bundle 'editorconfig/editorconfig-vim'
Bundle 'kien/ctrlp.vim'
Bundle 'MarcWeber/vim-addon-mw-utils'
Bundle 'tomtom/tlib_vim'
Bundle 'garbas/vim-snipmate'
Bundle 'scrooloose/snipmate-snippets'
Bundle 'tpope/vim-surround'
Bundle 'scrooloose/nerdcommenter'
Bundle 'scrooloose/nerdtree'
Bundle 'jistr/vim-nerdtree-tabs'
Bundle 'Shougo/neocomplcache'
Bundle 'Raimondi/delimitMate'
" Color Bundles
Bundle 'altercation/vim-colors-solarized'
" Syntax Bundles
Bundle 'tpope/vim-markdown'
Bundle 'kchmck/vim-coffee-script'
Bundle 'groenewege/vim-less'
Bundle 'aaronbieber/quicktask'
Bundle 'tpope/vim-fugitive'
Bundle 'terryma/vim-multiple-cursors'
" Required for neocomplcache
filetype plugin indent on
" ==============================================================================
" Configure Bundles
" ==============================================================================
" NERDTree
"map <C-e> :NERDTreeToggle<CR>:NERDTreeMirror<CR>
map <C-e> :NERDTreeTabsToggle<CR>
let NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr']
let NERDTreeMouseMode=2
" Neocomplcache
let g:neocomplcache_enable_at_startup = 1
" Ctrl-P
" Search from the root of the project
let g:ctrlp_working_path_mode = 'ra'
set wildignore+=*/node_modules/*,*test*,*/compiled/*,*/packages/*,*/audio/*,*ve/*,*/libs/*,*.png,*.jpg,*/public/*,*/thirdparty/*,*/swag/*
let g:airline_powerline_fonts = 1
" ==============================================================================
" Functions
" ==============================================================================
" A function to quickly toggle between light and dark backgrounds
function! ToggleBackground()
if g:background ==# "dark"
call LightBackground()
else
call DarkBackground()
endif
endfunction
" Set a light background
function! LightBackground()
let g:background = "light"
set background=light
highlight clear CursorLine
"color solarized
colorscheme Tomorrow
highlight ColorColumn ctermbg=254
highlight CursorLine ctermbg=254 cterm=none
endfunction
" Set a dark background
function! DarkBackground()
let g:background = "dark"
set background=dark
highlight clear CursorLine
"color solarized
colorscheme Tomorrow-Night-Eighties
highlight ColorColumn ctermbg=237
highlight CursorLine ctermbg=237 cterm=none
endfunction
" ==============================================================================
" Movement & Interaction
" ==============================================================================
" Movement between windows
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-L> <C-W>l
map <C-H> <C-W>h
" Get mouse working in panes
set ttyfast
set mouse=a
set ttymouse=xterm2
set mousehide
" Tab commands for faster navigation
set splitbelow
set splitright
nnoremap <S-h> gT
nnoremap <S-l> gt
nnoremap ZA :qa!<cr>
nnoremap <C-n> :tabnew<CR>
nnoremap <C-a> :e#<CR>
" Movements to begning and end of the line
inoremap <C-e> <End>
inoremap <C-a> <Home>
" Move the windows up and down
nnoremap <Down> <C-e>
nnoremap <Up> <C-y>
" ==============================================================================
" Misc
" ==============================================================================
set is " Incremental search by default
set noautochdir " Keep the working directory Vim was booted from
set expandtab " Only use spaces for tabs
set tabstop=4 " Tabs are 4 spaces
set softtabstop=4 " Soft tabs are 4 spaces
set shiftwidth=4 " Shifts are 4 spaces
set bs=2 " Backspacing without restrictions
set nosmartindent " ???
set nocindent " ???
set autoindent " Indent same as prev line
set number " Line numbers by default
set nowrap " Wrap long lines
set wrap
set linebreak
set relativenumber
set nolist " list disables linebreak
set hidden " Buffer switching without saves
set clipboard=unnamed " Use OSX clipboard in vim
set hlsearch " Highlight search terms
set ignorecase " Case insensitive search
set smartcase " Case sensitive when uc present
set wildmenu " Show list instead of just completing
set wildmode=list:longest,full " Command <Tab> completion in : mode
set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too
set spell
" ==============================================================================
" Visual Changes
" ==============================================================================
set title " Set the filename for title
if has("gui_running")
set guifont=Inconsolata:h16
endif
call DarkBackground()
set background=dark
" Hide useless scrollbars
set guioptions-=r
set guioptions-=L
" Status line stuff
set laststatus=2 " Always display
set statusline=%f " Path to the file
set statusline+=\ %m
set statusline+=%= " Go to the right side
set statusline+=(%4l " Current line
set statusline+=/ " Separator
set statusline+=%4L)\ " Total lines
set statusline+=%y\ " Filetype of the file
" More coloring stuff
syntax on " Always highlight syntax
set cursorline " Highlight the crnt line
"set textwidth=80 " Set a visual column at 80
"set colorcolumn=+1
" ==============================================================================
" Fat Finger Solutions
" ==============================================================================
let mapleader=","
" Save the use of shift key with ;
nnoremap ; :
" Repeat last character search with ;;
nnoremap ;; ;
" Move up and down through soft breaks
nnoremap j gj
nnoremap k gk
" Yank till end of line
nnoremap Y y$
" Don't exit out of visual mode when indenting
vnoremap < <gv
vnoremap > >gv
" ==============================================================================
" Filetype Specifics
" ==============================================================================
autocmd BufRead,BufNewFile *rc set filetype=sh
autocmd BufRead,BufNewFile .vimrc set filetype=vim
autocmd BufRead,BufNewFile *hbs set filetype=html
" Delete trailing whitespace
autocmd BufWritePre * :%s/\s\+$//e
" ==============================================================================
" Experiments
" ==============================================================================
nnoremap <leader>ev :tabe $MYVIMRC<cr> " Open the ~/.vimrc file
nnoremap <leader>sv :source $MYVIMRC<cr> " Re-Load the ~/.vimrc file
nnoremap <leader>l :e<cr> " Reload the current buffer
" Change the cursor depending on what mode your in (iTerm2) [MAGIC!]
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
if &term =~ "xterm.*"
let &t_ti = &t_ti . "\e[?1004h"
let &t_te = "\e[?1004l" . &t_te
map <ESC>[O :wa<CR>
endif
nnoremap <C-c> <esc>r<C-k>OK
inoremap <C-c> <esc>r<C-k>OK
nnoremap <C-x> <esc>r<C-k>XX
inoremap <C-x> <esc>r<C-k>XX
" Store swap files in fixed location, not current directory.
set dir=~/.vimswap//,/var/tmp//,/tmp//,.
set noswapfile
" ==============================================================================
" Function Keys
" ==============================================================================
nnoremap <F1> :call ToggleBackground()<CR>
nnoremap <F2> :set nospell!<CR>
nnoremap <F3> :set invpaste paste?<CR>
nnoremap <F4> :setlocal scrolloff=90<CR>
" ==============================================================================
" MACROS 4 LYFE
" ==============================================================================
" Add a , at the end of line
nnoremap <leader>, mqA,<esc>`q
inoremap ,, <esc>mqA,<esc>`qa
" Add a ; at the end of line
nnoremap <leader>. mqA;<esc>`q
inoremap ;; <esc>mqA;<esc>`qa
" Delete the last character of a line
nnoremap <leader>d mqA<esc>x`q
inoremap <C-d> <esc>mqA<esc>x`qa
" jQuerify a word: this -> $(this)
nnoremap <leader>sj mqebi$(<esc>ea)<esc>`qll
vnoremap <leader>sj c$()<esc>hp
"nnoremap <C-b> mqciw**<C-r>***<Esc>`qll
"vnoremap <C-b> mqc**<C-r>***<Esc>`qll
"nnoremap <C-i> mqciw*<C-r>**<Esc>`ql
"vnoremap <C-i> mqc*<C-r>**<Esc>`ql
" Surround code in a function
map <leader>sf >dOfunction() {<cr>}<esc>Pkf)i
" ==============================================================================
" Code Folding
" ==============================================================================
"set foldmethod=indent
"setlocal foldlevel=99
"nnoremap <space> za
" ==============================================================================
" Load Machine Specific Settings
" ==============================================================================
if filereadable(glob("~/.vimrc.local"))
source ~/.vimrc.local
endif
" ==============================================================================
" Fugitive
" ==============================================================================
nnoremap <leader>gs :Gstatus<cr>
nnoremap <leader>gd :Gdiff<cr>
nnoremap <leader>gb :Gbrowse<cr>
nnoremap <leader>gc :Gcommit<cr>
" ==============================================================================
" Multi Cursors
" ==============================================================================
let g:multi_cursor_use_default_mapping=0
let g:multi_cursor_next_key='<C-d>'
let g:multi_cursor_prev_key='<C-D>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'
" I{"team":€ü "f[i€kb", members": F,a€kr"A},j
" :%s/'/r€kb="€kb€kb"/g
nnoremap <leader>g :set operatorfunc=<SID>GrepOperator<cr>g@
vnoremap <leader>g :<c-u>call <SID>GrepOperator(visualmode())<cr>
function! s:GrepOperator(type)
let saved_unnamed_register = @@
if a:type ==# 'v'
normal! `<v`>y
elseif a:type ==# 'char'
normal! `[v`]y
else
return
endif
silent execute "grep! -R " . shellescape(@@) . " ."
copen
let @@ = saved_unnamed_register
endfunction
let &colorcolumn=join(range(81,999),",")
highlight ColorColumn ctermbg=235 guibg=#2c2d27
let &colorcolumn="80,".join(range(120,999),",")
" ==============================================================================
" Set up the silver searcher for way faster searching
" ==============================================================================
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
" Quick searching in projects
" Use K to search for word under the cursor
nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
nnoremap <leader>rr <esc>:%s /<c-r><c-w>//gc<Left><Left><Left>
nnoremap <leader>tt <esc>:grep /TODO/gj **<cr>:cw<cr>
nnoremap <leader>mm <esc>:grep /FIXME/gj **<cr>:cw<cr>
" bind \ (backward slash) to grep shortcut
command -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
nnoremap \ :Ag<SPACE>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment