Skip to content

Instantly share code, notes, and snippets.

@gilbertw1
Last active August 3, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilbertw1/66b69a10a6aa6b910fe4e2370bab6b50 to your computer and use it in GitHub Desktop.
Save gilbertw1/66b69a10a6aa6b910fe4e2370bab6b50 to your computer and use it in GitHub Desktop.
set nocompatible
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
if (has("nvim"))
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
set ttyfast " Faster terminal
endif
if (has("termguicolors"))
set termguicolors
endif
" Plugins
call plug#begin('~/vim/bundle')
Plug 'tpope/vim-fugitive' " git in vim
Plug 'sheerun/vim-polyglot' " support for a variety of languages
Plug 'vim-scripts/vis' " improved visual commands
Plug 'moll/vim-bbye' " kill buffers without affecting window layout
Plug 'rakr/vim-one' " one dark colorscheme
Plug 'Shougo/deoplete.nvim' " simple autocomplete
Plug 'szw/vim-maximizer' " toggling maximizing of a buffer
Plug 'justinmk/vim-sneak' " 2-character search motions
Plug 'Raimondi/delimitMate' " autoclose delimiters
Plug 'godlygeek/tabular' " for aligning text
Plug 'tomtom/tcomment_vim' " comment out code with native comment syntax
Plug 'tpope/vim-surround' " manipulation of surrounding delimiters
Plug 'AndrewRadev/switch.vim' " switching between true/false, yes/no, etc
Plug 'terryma/vim-expand-region' " easily expand regions using scopes
Plug 'airblade/vim-gitgutter' " visual git diffs in the gutter
Plug 'thinca/vim-visualstar' " smarter * and #
Plug 'vim-scripts/PickAColor.vim' " color picker pop-up
Plug 'airblade/vim-rooter' " working directory == project root
Plug 'scrooloose/nerdtree' " file explorer sidebar
Plug 'kien/ctrlp.vim' " Go-to-anything/Command-T
Plug 'tacahiroy/ctrlp-funky' " extension for jumping to functions
Plug 'jasoncodes/ctrlp-modified.vim' " extension for listing git modified files
Plug 'rking/ag.vim' " file searching
Plug 'vim-airline/vim-airline' " lightweight statusbar
call plug#end()
" Set encoding to utf-8
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8
set bomb
set binary
" Set python
let g:python_host_prog='/usr/bin/python'
""""""""""""""""""""
" APPEARANCE "
""""""""""""""""""""
" Turn syntax highlighting on
syntax on
filetype plugin on
colorscheme one
set background=dark
" Turn on line numbers
set number
" Highlight current line
set cursorline
" Show commands issued
set showcmd
" Questionable appearance settings
set fillchars=vert:│
set list
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
""""""""""""""""""""
" BEHAVIOR "
""""""""""""""""""""
" Auto update file that's been edited externally
set autoread
set backspace=indent,eol,start
set fileformats+=mac
" Allow buffer switching without saving
set hidden
" Don't update the screen too often
set lazyredraw
set noeol
" No sounds
set visualbell
" Word boundaries
set iskeyword-=.
set iskeyword-=_
set iskeyword-=#
" Show buffer name in tmux
set titlestring=%f%m
set title
" real tab
":inoremap <S-Tab> <C-V><Tab>
" Switch to current file directory
autocmd BufEnter * silent! lcd %:p:h
" Automatically close the popup menu
au InsertLEave * if pumvisible() == 0|silent! pclose|endif
" Do syntax highlighting from start
au BufEnter * :syntax sync fromstart
" Enable clipboard
if has('unnamedplus')
set clipboard=unnamed,unnamedplus
else
set clipboard=unnamed
endif
augroup vimrc-remember-cursor-position
au!
au BufWinEnter * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
" Instead of reverting the cursor to the last position in the buffer, we
" set it to the first line when editing a git commit message
au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
augroup END
""""""""""""""""""""
" MOVEMENT "
""""""""""""""""""""
set nostartofline
set sidescrolloff=5
set incsearch " find as you type
set hlsearch " Highlight search terms
set ignorecase " case insensitive search
set smartcase " case sensitive when uc present
set gdefault " global flag for substitute by default
""""""""""""""""""""
" FORMATTING "
""""""""""""""""""""
filetype plugin indent on
set autoindent
set expandtab
set shiftround
set shiftwidth=2 tabstop=2 softtabstop=2
set nowrap
" see :h fo-table
set formatoptions=qrn1lr
" Turn off auto-commenting lines
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
function! <SID>StripTrailingWhitespaces()
if &ft =~ 'vim'
return
endif
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfunction
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
""""""""""""""""""""
" PERSISTENTENCE "
""""""""""""""""""""
set nobackup
set nowritebackup
set noswapfile
if has('persistent_undo')
set undodir=~/.vim/tmp/undo
set undolevels=500
set undoreload=500
endif
set history=5000
" preserve buffer state (cursor location, folds, etc.)
set viewdir=~/.vim/tmp/views
set viewoptions=cursor,folds,unix,slash
augroup vimrc-persistence
au!
au BufWinLeave * if expand("%") != "" | silent! mkview | endif
au BufWinEnter * if expand("%") != "" | silent! loadview | endif
augroup END
""""""""""""""""""""
" PLUGINS "
""""""""""""""""""""
" deoplete
let g:deoplete#enable_at_startup = 1
" rebind deoplete up/down
inoremap <expr><c-k> pumvisible() ? "\<c-p>" : "\<c-k>"
inoremap <expr><c-j> pumvisible() ? "\<c-n>" : "\<c-j>"
" airline
let g:airline_powerline_fonts = 1
let g:airline_theme='one'
" easymotion
" let g:EasyMotion_startofline = 0
" vim-maximizer
let g:maximizer_set_default_mapping = 0
nnoremap <silent> <C-w>o :<C-u>MaximizerToggle!<CR>
" vim-sneak
let g:sneak#label = 1
" delimitMate
let g:delimitMate_expand_cr = 1
let g:delimitMate_expand_space = 1
" tcomment_vim
let g:tcomment_types = {'blade': '{-- %s --}', 'twig': '{# %s #}'}
" gitgutter
let g:gitgutter_eager = 0
" vim-rooter
let g:rooter_manual_only = 1
" NERDTree
let NERDTreeChDirMode = 2
let NERDTreeMinimalUI = 1
let NERDTreeShowHidden = 1
let NERDTreeIgnore = ['\~$', '\.swo$', '\.swp$', '\.git$', '\.hg', '\.svn', '\.bzr', '\.settings', '\.project', '\.DS_Store']
" ctrlp
if executable('ag')
let s:ctrlp_fallback = 'ag %s --nocolor -l -g ""'
else
let s:ctrlp_fallback = 'find %s -type f'
endif
if exists("g:ctrlp_user_command")
unlet g:ctrlp_user_command
endif
let g:ctrlp_extensions = ['tag', 'buffertag', 'funky']
let g:ctrlp_cache_dir = "~/.vim/tmp/ctrlp"
let g:ctrlp_match_window = 'bottom,order:btt,min:10,max:10,results:10'
let g:ctrlp_custom_ignore = {
\ 'dir': '\.(git|hg|svn|settings)$|tmp$',
\ 'file': '\.(exe|so|dll|sass-cache|classpaths|project|cache|jpg|png|gif|swf)$'
\ }
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'],
\ 2: ['.hg', 'hg --cwd %s locate -I .'],
\ },
\ 'fallback': s:ctrlp_fallback
\ }
""""""""""""""""""""
" KEYBINDINGS "
""""""""""""""""""""
" remap leader to space bar
let mapleader = "\<Space>"
" Normalize all the navigation keys to move by row/col despite any wrapped text
noremap j gj
noremap k gk
" don't yank empty line
nnoremap <expr> dd match(getline('.'), '^\s*$') == -1 ? 'dd' : '"_dd'
" Jump to beginning of line
nnoremap H ^
vnoremap H ^
"Jump to end of line
nnoremap L g_
vnoremap L g_
" Make Y act consistant with C and D
nnoremap Y y$
" Don't leave visual mode after indenting
vnoremap < <gv
vnoremap > >gv
" Prevent yanking
nnoremap c "_c
nnoremap C "_C
nnoremap X "_X
" Set paste toggle to F2
set pastetoggle=<F2>
" Turn off search highlighting
noremap <silent> <leader>? :nohlsearch<CR>
nnoremap <silent> <leader>; :CtrlPFunky<CR>
nnoremap <silent> <leader>fm :CtrlPModified<CR>
nnoremap <silent> <leader>] :CtrlPBufTag<CR>
nnoremap <silent> <leader>} :CtrlPBufTagAll<CR>
" NERDTree
map <localleader>\ :NERDTree <C-r>=FindRootDirectory()<CR><CR>
map <localleader>. :NERDTreeFind<CR>
" Tabularize
nmap <leader>= :Tabularize /
vmap <leader>= :Tabularize /
" Sneak
"replace 'f' with 1-char Sneak
nmap f <Plug>Sneak_f
nmap F <Plug>Sneak_F
xmap f <Plug>Sneak_f
xmap F <Plug>Sneak_F
omap f <Plug>Sneak_f
omap F <Plug>Sneak_F
"replace 't' with 1-char Sneak
nmap t <Plug>Sneak_t
nmap T <Plug>Sneak_T
xmap t <Plug>Sneak_t
xmap T <Plug>Sneak_T
omap t <Plug>Sneak_t
omap T <Plug>Sneak_T
" Sudo save
com! WW w !sudo tee % >/dev/null
" vim-switch
nnoremap ! :Switch<CR>
" EMACS-LIKE
noremap <silent> <leader><Tab> :b#<CR>
" Project
nnoremap <silent> <leader>pr :CtrlPMRU<CR>
nnoremap <silent><expr> <leader>pf getcwd() != $HOME ? ":<C-u>CtrlP<CR>" : ":<C-u>echoe 'Cannot open CtrlP in HOME'<CR>"
nnoremap <silent> <leader>pt :NERDTreeToggle <C-r>=FindRootDirectory()<CR><CR>
" File
nnoremap <silent> <leader>ff :CtrlPCurFile<CR>
nnoremap <silent> <leader>fs :w<CR>
nnoremap <silent> <leader>ft :NERDTreeToggle<CR>
" Buffer
nnoremap <silent> <leader>bb :CtrlPBuffer<CR>
" Editing
nnoremap <C-l> zz
" Window
nnoremap <silent> <leader>wm :<C-u>MaximizerToggle!<CR>
" vim:set ft=vim:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment