Skip to content

Instantly share code, notes, and snippets.

@jkachmar
Created June 29, 2016 17:06
Show Gist options
  • Save jkachmar/87113f1ae4e6cb906805b4cc3300df59 to your computer and use it in GitHub Desktop.
Save jkachmar/87113f1ae4e6cb906805b4cc3300df59 to your computer and use it in GitHub Desktop.
vim dotfiles
" -----------------------------------------------------------------------------
" Essential configuration
" -----------------------------------------------------------------------------
set nocompatible
" Space is a great leader
let mapleader = " "
set backspace=2 " backspace deletes like most programs in insert mode
set mouse=a
set nobackup
set nowritebackup
set noswapfile
set history=50
set ruler " show the cursor all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set laststatus=2 " always display the status line
set autowrite " automatically :write before running commands
set visualbell
set wildmenu
set wildmode=full
set incsearch
" -----------------------------------------------------------------------------
" Load external plugins
" -----------------------------------------------------------------------------
if filereadable(expand("~/.vimrc.plugins"))
source ~/.vimrc.plugins
endif
" -----------------------------------------------------------------------------
" Indentation and spacing
" -----------------------------------------------------------------------------
filetype plugin indent on
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set shiftround
set expandtab
" Display extra whitespace
set list listchars=tab:»·,trail:·,nbsp:·
" Use one space, not two, after punctuation.
set nojoinspaces
" Show 80 character delimitation
set textwidth=80
set colorcolumn=+1
" Numbering
set relativenumber number
set numberwidth=5
" Tab completion
" will insert tab at beginning of line,
" will use completion if not at beginning
set wildmode=list:longest,list:full
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <Tab> <c-r>=InsertTabWrapper()<cr>
inoremap <S-Tab> <c-n>
" -----------------------------------------------------------------------------
" Ctrlp & Ag
" -----------------------------------------------------------------------------
let g:ctrlp_user_command = 'ag %s -i --nogroup
\ --ignore .DS_Store
\ --ignore "**/*.pyc"
\ --ignore lib
\ --ignore "\v[\/](node_modules|target|dist|undo|plugged)$"
\ --ignore "\v[\/](\.(swp|ico|git|svn|hg))$"
\ -g ""'
let g:ctrlp_regexp = 1
let g:ctrlp_use_caching = 0
let g:ctrlp_working_path_mode = 0
let g:ctrlp_switch_buffer = 0
let g:ackprg = 'ag --nogroup --column'
set grepprg=ag\ --nogroup\ --nocolor
nnoremap <leader>a :Ag<space>
" -----------------------------------------------------------------------------
" NERDTree
" -----------------------------------------------------------------------------
map <leader>f :NERDTreeToggle<CR>
let NERDTreeShowHidden=1
let NERDTreeQuitOnOpen=1
" Switch between the last two files
nnoremap <leader>b <c-^>
" -----------------------------------------------------------------------------
" Autocompletion
" -----------------------------------------------------------------------------
"Note: This option must set it in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplete.
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 3
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
" Define dictionary.
let g:neocomplete#sources#dictionary#dictionaries = {
\ 'default' : '',
\ 'vimshell' : $HOME.'/.vimshell_hist',
\ 'scheme' : $HOME.'/.gosh_completions'
\ }
" Define keyword.
if !exists('g:neocomplete#keyword_patterns')
let g:neocomplete#keyword_patterns = {}
endif
let g:neocomplete#keyword_patterns['default'] = '\h\w*'
" Plugin key-mappings.
inoremap <expr><C-g> neocomplete#undo_completion()
inoremap <expr><C-l> neocomplete#complete_common_string()
" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
" For no inserting <CR> key.
"return pumvisible() ? "\<C-y>" : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
" ----------------------------------------------------------------------------
" Fugitive
" ----------------------------------------------------------------------------
nnoremap <silent> <leader>gs :<C-u>Gstatus<CR>
nnoremap <silent> <leader>gw :<C-u>Gwrite<CR>
nnoremap <silent> <leader>gc :<C-u>Gcommit<CR>
nnoremap <silent> <leader>gb :<C-u>Gblame<CR>
nnoremap <silent> <leader>gd :<C-u>Gdiff<CR>
nnoremap <silent> <leader>gj :<C-u>Gpull<CR>
nnoremap <silent> <leader>gk :<C-u>Gpush<CR>
nnoremap <silent> <leader>gf :<C-u>Gfetch<CR>
" -----------------------------------------------------------------------------
" Syntastic
" -----------------------------------------------------------------------------
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_check_on_open=0
let g:syntastic_aggregate_errors=1
let g:syntastic_error_symbol='x'
let g:syntastic_warning_symbol='!'
let g:syntastic_style_error_symbol='x'
let g:syntastic_style_warning_symbol='!'
" -----------------------------------------------------------------------------
" Window movement
" -----------------------------------------------------------------------------
" Open new split panes to right and bottom, which feels more natural
set splitbelow
set splitright
" Quicker window movement
nnoremap <leader>wj <C-w>j
nnoremap <leader>wk <C-w>k
nnoremap <leader>wh <C-w>h
nnoremap <leader>wl <C-w>l
" Always use vertical diffs
set diffopt+=vertical
" -----------------------------------------------------------------------------
" Remapping
" -----------------------------------------------------------------------------
nnoremap <silent> <leader><CR> :nohlsearch<Bar>:echo<CR>
vmap < <gv
vmap > >gv
" -----------------------------------------------------------------------------
" Interface
" -----------------------------------------------------------------------------
" Change cursor shape between insert and normal mode
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
let g:rainbow_active=1
" -----------
" | Airline |
" -----------
set hidden
let g:airline_theme='gruvbox'
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#tabline#show_tab_nr = 1
" Powerline Symbols
let g:airline_powerline_fonts = 1
set ttimeoutlen=50
set laststatus=2
" -----------
" | Tabline |
" -----------
" This replicates the idea of closing a tab
nmap <leader>tk :bp <BAR> bd #<CR>
" This replaes :tabnew which is used to bind to this mapping
nmap <leader>tn :enew<cr>
" Move to the next buffer
nmap <leader>tl :bnext<CR>
" Move to the previous buffer
nmap <leader>th :bprevious<CR>
let g:airline#extensions#tabline#buffer_idx_mode = 1
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
" ---------
" | Theme |
" ---------
syntax enable
set background=dark
set t_Co=256
colorscheme gruvbox
if has('gui_running')
set guifont=Fira\ Code:h14
endif
set hlsearch
" -----------------------------------------------------------------------------
" Source .vimrc
" -----------------------------------------------------------------------------
map <leader>v :source ~/.vimrc<CR>
if has("autocmd")
autocmd bufwritepost .vimrc source $MYVIMRC
endif
if &compatible
set nocompatible
end
call plug#begin('~/.vim/plugged')
" Essentials
Plug 'benekastah/neomake'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'scrooloose/syntastic'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'Shougo/neocomplete.vim'
Plug 'Shougo/vimproc.vim', { 'do': 'make' }
" Git integration
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'airblade/vim-gitgutter'
" UI
Plug 'bling/vim-airline'
Plug 'luochen1990/rainbow'
Plug 'morhetz/gruvbox'
" Javascript
" Plug 'gavocanov/vim-js-indent', { 'for': 'javascript' }
Plug 'othree/yajs.vim', { 'for': 'javascript' }
Plug 'othree/es.next.syntax.vim', { 'for': 'javascript' }
Plug 'pangloss/vim-javascript', { 'for': 'javascript' }
call plug#end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment