Skip to content

Instantly share code, notes, and snippets.

@calbertts
Last active January 8, 2020 16:43
Show Gist options
  • Save calbertts/c542b4fa76a4749e7c132a062beba0f3 to your computer and use it in GitHub Desktop.
Save calbertts/c542b4fa76a4749e7c132a062beba0f3 to your computer and use it in GitHub Desktop.
Neovim config
let g:loaded_youcompleteme = 1
if empty(glob('~/.vim/autoload/plug.vim'))
silent execute "!curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
" Kepp selected test when fixing indentation
vnoremap < <gv
vnoremap > >gv
" use <tab> for trigger completion and navigate to the next complete item
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <Tab>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>"
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif
function! SetupCommandAbbrs(from, to)
exec 'cnoreabbrev <expr> '.a:from
\ .' ((getcmdtype() ==# ":" && getcmdline() ==# "'.a:from.'")'
\ .'? ("'.a:to.'") : ("'.a:from.'"))'
endfunction
" Use C to open coc config
call SetupCommandAbbrs('C', 'CocConfig')
autocmd FileType json syntax match Comment +\/\/.\+$+
"Snippets
" Use <C-l> for trigger snippet expand.
imap <C-l> <Plug>(coc-snippets-expand)
" Use <C-j> for select text for visual placeholder of snippet.
vmap <C-j> <Plug>(coc-snippets-select)
" Use <C-j> for jump to next placeholder, it's default of coc.nvim
let g:coc_snippet_next = '<c-j>'
" Use <C-k> for jump to previous placeholder, it's default of coc.nvim
let g:coc_snippet_prev = '<c-k>'
" Use <C-j> for both expand and jump (make expand higher priority.)
imap <C-j> <Plug>(coc-snippets-expand-jump)
inoremap <silent><expr> <TAB>
\ pumvisible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = '<tab>'
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() :
\"\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
command! -nargs=0 Prettier :CocCommand prettier.formatFile
vmap <leader>f <Plug>(coc-format-selected)<CR>
nmap <leader>f <Plug>(coc-format-selected)
" Ctags
"command! MakeTags !ctags -R .
"nnoremap <leader>rd <C-]>
"function! s:get_gutentags_status(mods) abort
" let l:msg = ''
" if index(a:mods, 'ctags') >= 0
" let l:msg .= '♨'
" endif
" if index(a:mods, 'cscope') >= 0
" let l:msg .= '♺'
" endif
" return l:msg
"endfunction
"set statusline+=%{gutentags#statusline_cb(
" \function('<SID>get_gutentags_status'))}
" enable gtags module
"let g:gutentags_modules = ['ctags', 'gtags_cscope']
" config project root markers.
"let g:gutentags_project_root = ['.root']
" generate datebases in my cache directory, prevent gtags files polluting my project
"let g:gutentags_cache_dir = expand('~/.cache/tags')
" forbid gutentags adding gtags databases
"let g:gutentags_auto_add_gtags_cscope = 0
" Easy motions
nmap F <Plug>(easymotion-prefix)s
" Limelight
nmap <Leader>L :Limelight!!<CR>
"Avoid ESCAPE key
"let g:easyescape_chars = { "j": 2 }
"let g:easyescape_timeout = 300
"cnoremap jj <ESC>
inoremap jj <Esc>
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" If doing a diff. Upon writing changes to file, automatically update the differences
autocmd BufWritePost * if &diff == 1 | diffupdate | endif
" Enable bash alias
"set shellcmdflag=-ic
" Persistent undo
set undofile
set undodir=$HOME/.vim/undo
set undolevels=1000
set undoreload=10000
" console.log snippet
"vmap cll yocll<Esc>p
"nmap cll yiwocll<Esc>p
" replace current selected text with last yanked text
vnoremap S "_d"0P
"Reload changes made out of vim
set autoread
"autocmd CursorHold,CursorHoldI,FocusGained,BufEnter * checktime
"autocmd FileChangedShellPost *
"" \ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None
"Diff colors
hi DiffAdd guifg=NONE ctermfg=NONE guibg=#464632 ctermbg=238 gui=NONE cterm=NONE
hi DiffChange guifg=NONE ctermfg=NONE guibg=#335261 ctermbg=239 gui=NONE cterm=NONE
hi DiffDelete guifg=#f43753 ctermfg=203 guibg=#79313c ctermbg=237 gui=NONE cterm=NONE
hi DiffText guifg=NONE ctermfg=NONE guibg=NONE ctermbg=NONE gui=reverse cterm=reverse
hi Folded ctermbg=237
"Colors
"hi Normal guifg=#c0c0c0 guibg=#272727
if (has("termguicolors"))
set termguicolors
endif
syntax enable
"New line without insert mode
nnoremap <C-J> a<CR><Esc>k$
"Enable mouse
set mouse=a
"Hightlight search
set hlsearch
nnoremap <CR> :nohlsearch<CR><CR>
"Folding options
"set re=1
"set foldmethod=indent
"set foldlevelstart=10
"Move all swp files to tmp folder
"set backupdir=$TMPDIR
"set directory=$TMPDIR
"Autocomplete
"imap <Leader><Tab><Tab> <plug>(fzf-complete-word)
"imap <Leader><Tab-1><1> <plug>(fzf-complete-path)
autocmd InsertEnter * :set number
autocmd InsertLeave * :set relativenumber
set rtp+=/usr/local/opt/fzf
syntax on
filetype plugin indent on
set expandtab
set cursorline
set noautoindent
set tabstop=2
set shiftwidth=2
set number
set nowrap
set numberwidth=5
set splitright
set splitbelow
set lazyredraw
set synmaxcol=2000
syntax sync minlines=500
set wildignore+=**/node_modules/**,**/dbData/**,**/jspm_packages/**,**/bundles/**,**/builds/**,**/dist/**
hi CursorLine cterm=NONE ctermbg=237 ctermfg=NONE
set fillchars+=vert:\│
hi clear VertSplit
hi LineNr ctermfg=grey
hi Visual guibg=black
let g:jsx_ext_required = 0
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'jsformatter'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#fnamemod = ':t'
set laststatus=2
set signcolumn=yes
let g:Powerline_symbols = 'fancy'
set encoding=utf-8
"let g:airline_theme="wombat"
let g:airline_theme="oceanicnextlight"
"let g:airline_theme='gruvbox'
set guifont=DroidSansMono\ Nerd\ Font\ 16
"let g:airline_left_sep = "\uE0B4"
"let g:airline_left_alt_sep = "⎞"
"let g:airline_right_sep = "\uE0B6"
let g:airline#extensions#tabline#show_tab_nr = 0
let $FZF_DEFAULT_COMMAND= 'ag -g ""'
nnoremap <silent> <Leader>ag :Ag <C-R><C-W><CR>
"Theme
let g:oceanic_next_terminal_bold = 1
let g:oceanic_next_terminal_italic = 1
let g:gruvbox_italic="1"
let g:gruvbox_contrast_dark="medium"
let g:gruvbox_contrast_light="medium"
let g:gruvbox_invert_selection="on"
let g:gruvbox_invert_signs=0
set background=light
colorscheme OceanicNextLight
"colorscheme gruvbox
"Cursors
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
"Javascript stuff
let g:javascript_plugin_jsdoc = 1
let g:javascript_plugin_ngdoc = 1
let g:javascript_plugin_flow = 1
" Linter options
"let g:ale_sign_error = 'X '
"let g:ale_sign_warning = '⁉ '
"let g:ale_sign_column_always = 0
"let g:airline#extensions#ale#enabled = 1
"let g:ale_completion_enabled = 1
"let g:ale_pattern_options = {
"\ '\.min\.js$': {'ale_linters': [], 'ale_fixers': []},
"\ '\.min\.css$': {'ale_linters': [], 'ale_fixers': []},
"\}
"let g:ale_linters = {
"\ 'javascript': ['eslint']
"\}
"let g:ale_fixers = {
"\ 'javascript': ['importjs'],
"\}
"Delete all whitespaces at the end of line
autocmd BufWritePre * %s/\s\+$//e
set rtp+=/Users/calbertts/.vim/plugged/powerline/bindings/vim
"keys stuff
set showcmd
let mapleader = "\<Space>"
"Horizontal scroll
map <C-L> 10zl " Scroll 10 characters to the right
map <C-H> 10zh " Scroll 10 characters to the left
"Working with files
"nnoremap <Leader>o :call fzf#vim#ag('')<CR>
nnoremap <Leader>o :FZF<CR>
nnoremap <Leader>O :call fzf#run({'source': 'find .', 'sink': 'e'})<CR>
nnoremap <Leader>w :b#\|bd #<CR>
nnoremap <Leader>W :b#\|bd! #<CR>
nnoremap <Leader>bl :bnext<CR>
nnoremap <Leader>bh :bprev<CR>
nnoremap <Leader>bs :Buffers<CR>
nnoremap <leader>bz <C-^>
nnoremap <Leader>bc :bd<CR>
noremap <C-N> :enew<CR>
" Environments
function! OpenEnvironment(env)
exe 'silent Nread scp://'.a:env.'/'
exe 'silent file '.a:env
endfunction
nnoremap <silent><Leader>E :silent call fzf#run({'down': '15', 'source': 'cat ~/.ssh/config \| grep "Host " \| sed "s/Host //g"', 'sink': function('OpenEnvironment')})<CR>
" set alternate color for modified active/inactive tabs
autocmd VimEnter *
\ let g:airline#themes#oceanicnextlight#palette.tabline = {
\ 'airline_tabmod': ['#f8f8f8','#780000',231,88,''],
\ 'airline_tabmod_unsel': ['#dddddd','#463030',231,52,''],
\ } | :AirlineRefresh
" Working with tabs
nnoremap <Leader>tn :tabnew<CR>
nnoremap <Leader>th :tabp<CR>
nnoremap <Leader>tl :tabn<CR>
nnoremap <Leader>tc :tabc<CR>
nnoremap <Leader>to :tabo<CR>
nnoremap <Leader>tp :tablast<CR>
nnoremap <Leader>cp :let @+=expand("%")<CR>
nnoremap <Leader>cfp :let @+=expand("%:p")<CR>
" Formatters
function! ApplyCSSFormat()
syntax off
%!formatcss
syntax on
endfunction
nnoremap <Leader>jb :%!python -m json.tool<CR>
nnoremap <Leader>cf :silent call ApplyCSSFormat()<CR>
" Git shorcuts
set updatetime=100
set diffopt+=vertical
nnoremap ? :GFiles?<CR>
nnoremap <Leader>gj :GitGutterNextHunk<CR>zz
nnoremap <Leader>gl :GitGutterPrevHunk<CR>zz
nnoremap <Leader>gu :GitGutterUndoHunk<CR>
nnoremap <Leader>gs :GitGutterStageHunk<CR>
nnoremap <Leader>gp :GitGutterPreviewHunk<CR>
nnoremap <Leader>go :GitGutterFold<CR>
nnoremap <Leader>gx :G<CR>
nnoremap <Leader>gc :Gdiffsplit!<CR>
function! DiffWithBranch(branch)
exe 'Gdiffsplit '.a:branch
endfunction
function! DiffWithTag(tag)
exe 'Gdiffsplit '.a:tag
endfunction
function! DiffWithCommit(tag)
exe 'Gdiffsplit '.a:tag
endfunction
nnoremap <Leader>gdh :Gdiffsplit HEAD<CR>
nnoremap <silent><Leader>gdb :silent call fzf#run({'down': '15', 'source': 'git --no-pager branch --all', 'sink': function('DiffWithBranch')})<CR>
nnoremap <silent><Leader>gdt :silent call fzf#run({'down': '15', 'source': 'git --no-pager tag -l \| grep account', 'sink': function('DiffWithTag')})<CR>
nnoremap <silent><Leader>gdc :silent call fzf#run({'down': '15', 'source': 'git log', 'sink': function('DiffWithCommit')})<CR>
" Rapid inserts
nnoremap <Leader>ib a{}<ESC>i
nnoremap <Leader>ic a[]<ESC>i
nnoremap <Leader>ip a()<ESC>i
nnoremap <Leader>io a\|\|<ESC>a
nnoremap <Leader>iu i\<ESC>a
"YouCompleteMe
"let g:ycm_filetype_blacklist = {
" \'json': 1
"\}
"let g:ycm_filetype_specific_completion_to_disable = {
" \'json': 1
"\}
"let g:ycm_autoclose_preview_window_after_completion = 1
"let g:ycm_autoclose_preview_window_after_insertion = 1
" Not to show preview window when autocomplete
"set completeopt-=preview
"let g:ycm_add_preview_to_completeopt = 0
" Read tags
"let g:ycm_collect_identifiers_from_tags_files = 1
" Defer load of YCM
"augroup load_ycm
" autocmd!
" autocmd CursorHold, CursorHoldI * :packadd YouCompleteMe
" \ | autocmd! load_ycm
"augroup END
let g:tern_show_signature_in_pum = 1
let g:tern_show_argument_hints = 'on_move'
nnoremap <Leader>rt :YcmCompleter GoTo<CR>
nnoremap <Leader>rr :YcmCompleter GoToReferences<CR>
nnoremap <Leader>rd :YcmCompleter GoToDefinition<CR>
"nnoremap <Leader>rd :YcmCompleter GetDoc<CR>
nnoremap <Leader>rf :YcmCompleter RefactorRename<CR>
"nnoremap <leader>f :vimgrep . "'" . expand("<cword>") . "'" . **/*.js<CR>
"Copy/Paste from clipboard
vnoremap <Leader>y "*y
nnoremap <Leader>p "+p
"Save
nnoremap <Leader>s :w<CR>
"Resize windows
nnoremap <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>
"Save folds
"augroup AutoSaveFolds
" autocmd!
" au BufWinLeave ?* mkview 1
" au BufWinEnter ?* silent loadview 1
"augroup END
nnoremap <C-W>O :call MaximizeToggle()<CR>
nnoremap <C-W>o :call MaximizeToggle()<CR>
nnoremap <C-W><C-O> :call MaximizeToggle()<CR>
function! MaximizeToggle()
if exists("s:maximize_session")
exec "source " . s:maximize_session
call delete(s:maximize_session)
unlet s:maximize_session
let &hidden=s:maximize_hidden_save
unlet s:maximize_hidden_save
else
let s:maximize_hidden_save = &hidden
let s:maximize_session = tempname()
set hidden
exec "mksession! " . s:maximize_session
only
endif
endfunction
" Workspaces
let g:workspace_session_name = 'Session.vim'
let g:workspace_autosave_ignore = ['gitcommit']
let g:workspace_autosave = 0
let g:workspace_autosave_untrailspaces = 0
if empty(glob('~/.vim/autoload/plug.vim'))
silent execute "!curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
noremap <silent> <c-u> :call smooth_scroll#up(&scroll, 0, 2)<CR>
noremap <silent> <c-d> :call smooth_scroll#down(&scroll, 0, 2)<CR>
noremap <silent> <c-b> :call smooth_scroll#up(&scroll*2, 0, 4)<CR>
noremap <silent> <c-f> :call smooth_scroll#down(&scroll*2, 0, 4)<CR>
" Terminal emulator
tnoremap <Esc> <C-\><C-n>
tnoremap <A-h> <C-\><C-N><C-w>h
tnoremap <A-j> <C-\><C-N><C-w>j
tnoremap <A-k> <C-\><C-N><C-w>k
tnoremap <A-l> <C-\><C-N><C-w>l
inoremap <A-h> <C-\><C-N><C-w>h
inoremap <A-j> <C-\><C-N><C-w>j
inoremap <A-k> <C-\><C-N><C-w>k
inoremap <A-l> <C-\><C-N><C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
function! OpenTerminalV()
exec "vsplit"
exec "set nonumber"
exec "set norelativenumber"
exec "set signcolumn=no"
exec "e term://bash --login"
endfunction
function! OpenTerminalH()
exec "split"
exec "set nonumber"
exec "set norelativenumber"
exec "set signcolumn=no"
exec "e term://bash --login"
endfunction
nnoremap <Leader>zv :silent call OpenTerminalV()<CR>
nnoremap <Leader>zh :silent call OpenTerminalH()<CR>
"nnoremap <leader>z :vsplit<CR>:terminal<CR>i<CR>source $HOME/.bash_profile<CR>
function! IndentIgnoringBlanks(child)
let lnum = v:lnum
while v:lnum > 1 && getline(v:lnum-1) == ""
normal k
let v:lnum = v:lnum - 1
endwhile
if a:child == ""
if ! &l:autoindent
return 0
elseif &l:cindent
return cindent(v:lnum)
endif
else
exec "let indent=".a:child
if indent != -1
return indent
endif
endif
if v:lnum == lnum && lnum != 1
return -1
endif
let next = nextnonblank(lnum)
if next == lnum
return -1
endif
if next != 0 && next-lnum <= lnum-v:lnum
return indent(next)
else
return indent(v:lnum-1)
endif
endfunction
command! -bar IndentIgnoringBlanks
\ if match(&l:indentexpr,'IndentIgnoringBlanks') == -1 |
\ if &l:indentexpr == '' |
\ let b:blanks_indentkeys = &l:indentkeys |
\ if &l:cindent |
\ let &l:indentkeys = &l:cinkeys |
\ else |
\ setlocal indentkeys=!^F,o,O |
\ endif |
\ endif |
\ let b:blanks_indentexpr = &l:indentexpr |
\ let &l:indentexpr = "IndentIgnoringBlanks('".
\ substitute(&l:indentexpr,"'","''","g")."')" |
\ endif
command! -bar IndentNormally
\ if exists('b:blanks_indentexpr') |
\ let &l:indentexpr = b:blanks_indentexpr |
\ endif |
\ if exists('b:blanks_indentkeys') |
\ let &l:indentkeys = b:blanks_indentkeys |
\ endif
augroup IndentIgnoringBlanks
au!
au FileType * IndentIgnoringBlanks
augroup END
" Plugins
call plug#begin('~/.vim/plugged')
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim' " Fuzzy finder
Plug 'thaerkh/vim-workspace' " Workspace manager
Plug 'maxmellon/vim-jsx-pretty' " Better JSX syntax hightligh
"Plug 'powerline/powerline' " Buttom info bar
Plug 'vim-airline/vim-airline' " Airline styles
Plug 'vim-airline/vim-airline-themes' " Airline themes
Plug 'airblade/vim-gitgutter' " Git gutter
Plug 'pangloss/vim-javascript' " Improved JS syntax
Plug 'mxw/vim-jsx' " Support JSX syntax
Plug 'tpope/vim-fugitive', { 'tag': 'v3.1' } " Git features
Plug 'scrooloose/nerdtree' " File tree viewer
"Plug 'w0rp/ale' " Asyncronous linter
Plug 'junegunn/rainbow_parentheses.vim'
Plug 'tpope/vim-surround' " ys ([{''}])
Plug 'Raimondi/delimitMate' " Autoclose ([{''}])
Plug 'mhartington/oceanic-next' " Color scheme
"Plug 'Valloric/YouCompleteMe' " Autocomplete
Plug 'juanpabloaj/vim-istanbul' " Code coverage
Plug 'junegunn/vim-easy-align' " Align declarations
Plug 'junegunn/limelight.vim' " Focus code
Plug 'easymotion/vim-easymotion' " Place cursor wherever you want
Plug 'morhetz/gruvbox' " Theme
"Plug 'ludovicchabant/vim-gutentags' " ctags automatic generation
"Plug 'skywind3000/gutentags_plus'
"Plug 'ashisha/image.vim' " Visualize images in Vim
Plug 'jimmyhchan/dustjs.vim'
Plug 'ruanyl/coverage.vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'posva/vim-vue'
Plug 'martinda/Jenkinsfile-vim-syntax'
Plug 'zxqfl/tabnine-vim' " Autocompleter with AI
Plug 'neoclide/coc.nvim', {'branch': 'release'}
"Plug 'lycoris0731/tweet.nvim', { 'do': 'make' }
call plug#end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment