set nocompatible let mapleader = "\" if empty(glob('~/.vim/autoload/plug.vim')) silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim autocmd VimEnter * PlugInstall | source $MYVIMRC endif call plug#begin('~/.cache/vim/plugs') Plug 'w0ng/vim-hybrid' " color scheme Plug 'mhinz/vim-startify' let g:startify_session_persistence = 1 let g:startify_session_autoload = 1 let g:startify_fortune_use_unicode = 1 let g:startify_update_oldfiles = 1 let g:startify_change_to_vcs_root = 1 let g:startify_change_to_dir = 0 let g:startify_lists = [ \ { 'type': 'dir', 'header': [' Recent '. getcwd()] }, \ { 'type': 'files', 'header': [' Recent'] }, \ { 'type': 'bookmarks', 'header': [' Bookmarks'] }, \ { 'type': 'sessions', 'header': [' Sessions'] }, \ { 'type': 'commands', 'header': [' Commands'] }, \ ] Plug 'tpope/vim-sensible' " Sensible defaults, duh " Out of the box support for many languages Plug 'sheerun/vim-polyglot', { 'tag': '*' } Plug 'octref/RootIgnore' " Populate wildignore option from local gitignores Plug 'scrooloose/nerdtree', { 'tag': '*' } let g:NERDTreeWinPos='right' let g:NERDTreeRespectWildIgnore=1 " Hide things from wildignore let g:NERDTreeMouseMode = 3 " Nerd tree: single clicks open file/dir let g:NERDTreeNaturalSort = 1 nmap tt :NERDTreeToggle nmap fo :NERDTreeFind "Plug 'tpope/vim-vinegar' " Nicer netrw let loaded_netrwPlugin=1 " Disable netrw completely http://stackoverflow.com/a/21687112 Plug 'mbbill/undotree', { 'on': ['UndotreeToggle', 'UndotreeFocus', 'UndotreeShow', 'UndotreeHide'] } let g:undotree_WindowLayout = 2 let g:undotree_SetFocusWhenToggle = 1 nmap u :UndotreeToggle nmap tu :UndotreeToggle Plug 'tpope/vim-commentary' " There is no ASCII char for Control+/ (common shortcut for commentign), but " most terminals match that key combo to Control+_, so we will capture that " instead. nmap gcc xmap gcgv imap gcc Plug 'tpope/vim-dispatch' Plug 'tpope/vim-eunuch' Plug 'tpope/vim-endwise' " Auto-add 'end' etc appropriately in various languages Plug 'tpope/vim-fugitive', {'tag': '*', 'branch': 'master'} Plug 'rhysd/committia.vim' " More convenient UI when using Vim as EDITOR for `git commit` Plug 'hotwatermorning/auto-git-diff' " Show diffs in split when doing a `git rebase -i` Plug 'tpope/vim-git' Plug 'tpope/vim-repeat' Plug 'tpope/vim-sleuth' " auto-config indent and tabs etc based on other files Plug 'tpope/vim-surround' " quoting/parenthesizing made simple Plug 'terryma/vim-expand-region' if has('signs') Plug 'airblade/vim-gitgutter' endif Plug 'kana/vim-smartinput' " smart pairwise characters Plug '~/.fzf' " Installation of bins handled by Fresh, separately Plug 'junegunn/fzf.vim' if executable('ag') let $FZF_DEFAULT_COMMAND = 'ag -l --hidden .' endif map :GFiles map :Files " autocmd FileType fzf nmap :q " make t, f, T, F, etc all multi-line Plug 'dahu/vim-fanfingtastic' " Preview register contents before selecting the register Plug 'junegunn/vim-peekaboo' Plug 'junegunn/vim-easy-align', { 'on': ['(EasyAlign)', 'EasyAlign'] } vmap (EasyAlign) " When re-opening a file, start cursor on last edit location Plug 'farmergreg/vim-lastplace' Plug 'thisivan/vim-matchit' " extended matching for html, latex, and many other languages Plug 'kana/vim-textobj-user' " Create new text objects Plug 'michaeljsmith/vim-indent-object' Plug 'haya14busa/incsearch.vim', { 'on': ['(incsearch-forward)', '(incsearch-backward)', '(incsearch-stay)']} Plug 'haya14busa/incsearch-fuzzy.vim', { 'on': ['(incsearch-fuzzy-/)', '(incsearch-fuzzy-?)', '(incsearch-fuzzy-stay)']} nmap / (incsearch-forward) xmap / (incsearch-forward) nmap ? (incsearch-backward) xmap ? (incsearch-backward) map g/ (incsearch-stay) map z/ (incsearch-fuzzy-/) map z? (incsearch-fuzzy-?) nmap zg/ (incsearch-fuzzy-stay) Plug 'Yggdroot/indentLine' let g:indentLine_color_term = 239 let g:indentLine_color_gui = '#504945' let g:indentLine_fileTypeExclude = ['help', 'man', 'startify', 'vimfiler', 'markdown'] let g:indentLine_char = '┊' " Run a find-and-replace using the last search term nnoremap :%s////g " Make * and # work with a visual selection (in normal mode, it falls back to " default behaviour of searching for current word) Plug 'thinca/vim-visualstar' Plug 'neoclide/coc.nvim', {'tag': '*', 'branch': 'release', 'do': { -> coc#util#install()}} Plug 'liuchengxu/vim-which-key' ", { 'on': ['WhichKey', 'WhichKey!'] } set timeoutlen=300 autocmd! User vim-which-key call which_key#register('', 'g:which_key_map') nnoremap :WhichKey '' Plug 'tpope/vim-bundler' Plug 'tpope/vim-rails' Plug 'tpope/vim-rake' Plug 'thisivan/vim-ruby-matchit' Plug 'nelstrom/vim-textobj-rubyblock', { 'for': 'ruby' } Plug 'gko/vim-coloresque' Plug 'w0rp/ale' let g:ale_fix_on_save = 1 let g:ale_completion_enabled = 1 let g:ale_fixers = { \ '*': ['remove_trailing_lines', 'trim_whitespace'], \ 'javascript': ['eslint'], \ 'ruby': ['rubocop'], \} Plug 'vim-airline/vim-airline' let g:airline_powerline_fonts = 1 let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#left_sep = ' ' let g:airline#extensions#tabline#left_alt_sep = '|' call plug#end() hi Normal ctermbg=none " if hidden not set, TextEdit might fail. set hidden " Better display for messages set cmdheight=2 " Smaller updatetime for CursorHold & CursorHoldI set updatetime=300 " always show signcolumns set signcolumn=yes " Use tab for trigger completion with characters ahead and navigate. " Use command ':verbose imap ' to make sure tab is not mapped by other plugin. inoremap \ pumvisible() ? "\" : \ check_back_space() ? "\" : \ coc#refresh() inoremap pumvisible() ? "\" : "\" function! s:check_back_space() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction " Use for trigger completion. inoremap coc#refresh() " Use for confirm completion, `u` means break undo chain at current position. " Coc only does snippet and additional edit on confirm. "inoremap pumvisible() ? "\" : "\u\" " NOTE: above mapping disabled due to https://github.com/tpope/vim-endwise/issues/22#issuecomment-446042476 " Use `[c` and `]c` for navigate diagnostics nmap [c (coc-diagnostic-prev) nmap ]c (coc-diagnostic-next) " Remap keys for gotos nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) " Use K for show documentation in preview window nnoremap K :call show_documentation() function! s:show_documentation() if &filetype == 'vim' execute 'h '.expand('') else call CocAction('doHover') endif endfunction " Highlight symbol under cursor on CursorHold autocmd CursorHold * silent call CocActionAsync('highlight') " Remap for rename current word nmap rn (coc-rename) " Remap for format selected region vmap f (coc-format-selected) nmap f (coc-format-selected) " Setup formatexpr specified filetype(s). augroup mygroup autocmd! autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') augroup end " Remap for do codeAction of selected region, ex: `aap` for current paragraph vmap a (coc-codeaction-selected) nmap a (coc-codeaction-selected) " Remap for do codeAction of current line nmap ac (coc-codeaction) syntax on " Visual set ruler set guioptions=ce set showmatch " Briefly jump to a paren once it's balanced set linespace=2 set background=dark set laststatus=2 colorscheme hybrid " Tabs/Whitespace set tabstop=2 " a Tab take up 2 spaces set shiftwidth=2 " (un)indent 2 spaces at at ime set autoindent " preserve previous indent level when inserting new line set smarttab " insert/delete a tab's work of spaces at a time set expandtab " insert actual spaces, not tabs set nowrap " don't wrap long lines set backspace=indent,eol,start " allow backspacing over everything in insert mode " Toggle show tabs and trailing spaces (,c) set list set listchars=tab:⤑\ ,trail:·,eol:↵,nbsp:_ set fillchars=vert:\ ,fold:- nnoremap tc :set list! list? " Misc set switchbuf=useopen " Don't re-open already opened buffers set nostartofline " Avoid moving cursor to BOL when jumping around set virtualedit=all " Let cursor move past the last char set whichwrap=b,s,h,l,<,>,[,] set autoread " watch for file changes set mouse=a " mouse can be handy sometimes if !has('nvim') set ttymouse=xterm2 " Needed to get mouse working when in Tmux/screen endif set fileformats=unix set history=1000 set title " Show title in Terminal " Bells set visualbell set noerrorbells " No noise. set vb t_vb= " disable any beeps or flashes on error " Searching set hlsearch " highlight search matches and keep them highlighted set incsearch " start matching search before hitting enter set ignorecase " case-insensitive searching by default set smartcase " but if searching with multiple cases, treat it as case-sensitive " center current search result in middle of screen nnoremap n nzz nnoremap N Nzz nnoremap * *zz nnoremap # #zz nnoremap g* g*zz nnoremap g# g#zz " Work around bug that leaves cursor in middle of line nnoremap dd ddI " Tab completion set wildmode=list:longest,list:full set wildignore+=*.o,*.obj,.git,*.rbc,*.swp " Directories for swp files " Navigate cursor up/down by lines on screen, not lines in file nmap j gj nmap k gk " Reselect visual block after adjusting indentation vnoremap < >gv " Adjust indentation with single keypress nnoremap < << nnoremap > >> " Nicer splitting set splitbelow set splitright " Emacs-like keys for the command line and insert mode noremap! noremap! " Always show cursorline, but only in current window. set scrolloff=3 set scrolljump=10 set number " line numbers set relativenumber " I keep deleting words when I want to switch windows imap " Map control-S to save ( makes sure no range is inserted into command " execution) nmap :w vmap :wgv " Share clipboard with OS set clipboard=unnamed,unnamedplus " May only work in iTerm2 and may have other bad effects, " but this shows a block in normal mode, and vertical bar " in insert mode. if exists('$TMUX') " https://github.com/sjl/vitality.vim/issues/8#issuecomment-7664649 let &t_SI = "\[3 q" let &t_EI = "\[0 q" if !has('nvim') set term=screen-256color endif else let &t_SI = "\]50;CursorShape=1\x7" let &t_EI = "\]50;CursorShape=0\x7" endif runtime macros/matchit.vim function! StripTrailingWhitespaces() " Preparation: save last search, and cursor position. let _s=@/ let l = line(".") let c = col(".") " Do the business: %s/\s\+$//e " Clean up: restore previous search history, and cursor position let @/=_s call cursor(l, c) endfunction " Strip trailing whitespace on command nmap sw :call StripTrailingWhitespaces() augroup the_rest au! if !has('nvim') " Attempted fix for Vim losing mouse support when inside Tmux autocmd TermResponse,CursorHold,CursorHoldI * set ttymouse=xterm2 endif " Create parent directory if it doesn't exist before writing file " (http://stackoverflow.com/questions/4292733/vim-creating-parent-directories-on-save) autocmd BufWritePre * if expand("")!~#'^\w\+:/' && !isdirectory(expand("%:h")) | execute "silent! !mkdir -p ".shellescape(expand('%:h'), 1) | redraw! | endif " make and python use real tabs autocmd FileType make set noexpandtab autocmd FileType python set noexpandtab autocmd BufRead,BufNewFile gitconfig set ft=gitconfig " Strip trailing whitespace on save autocmd BufWritePre * :call StripTrailingWhitespaces() augroup end silent! !bash -c "mkdir -p ~/.cache/vim/{backups,swaps,undos} &>/dev/null" set undofile " persistent undos set undodir=~/.cache/vim/undos// " where to store undo histories (trailing // is important) set directory=~/.cache/vim/swaps// " store swap files here (trailing // is important) set backupdir=~/.cache/vim/backups// " store file backups here (trailing // is important) set backupskip=/tmp/*,/private/tmp/*" " don't use backups for tmp files set autoread set modeline set modelines=5 " For when you forget to sudo.. Really Write the file. cmap w!! w !sudo tee % >/dev/null " CTags map rt :!ctags --extra=+f -R * set tags=tmp/tags;/,./tmp/tags;/,tags;/,./tags;/ nmap tp :set invpaste paste? nmap tn :set invnumber number? nmap tr :set invrelativenumber relativenumber? if executable('ag') let g:ackprg = 'ag --vimgrep --hidden' endif " comment line " For working on highlight/syntax rules map :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" " I pretty much only work with Postgres SQL, so assume *.sql files belong to " that syntax: let g:sql_type_default = 'pgsql' " Make copy/paste work kinda normally " " https://stackoverflow.com/a/14786750/1155048 set pastetoggle= inoremap + vnoremap "+y " Copy current file path to clipboard nnoremap :let @+ = expand("%:p") \| echo '"' . expand("%:p") . '" copied to clipboard.' " Search for current visual selection vnoremap y/" " Bubble lines up/down nmap :m-2 nmap :m+1 nmap :m-2 nmap :m+1 vmap :m-2gv vmap :m'>+1gv vmap :m-2gv vmap :m'>+1gv " highlight last inserted text nnoremap gV `[v`] nmap [b :bprevious nmap ]b :bnext nmap ]t :tprevious nmap [t :tnext " Show incremental previews of commands (such as :s[ubstitute]) set inccommand=nosplit " Start elixir tooling with a custom MIX_ENV so that compilation by that " tooling doesn't negatively affect Phoenix auto-reloading " " https://github.com/phoenixframework/phoenix/issues/1165#issuecomment-437130681 let $MIX_ENV='editor' if filereadable(expand('~/.vimrc.local')) source ~/.vimrc.local endif