Last active
December 6, 2019 18:13
-
-
Save kcoyner/32199d4a6fe25779918e649c466c1cb2 to your computer and use it in GitHub Desktop.
vimrc file for use with nvim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ============================================================================ " | |
" === kcoyner's nvim config === " | |
" ============================================================================ " | |
" Plugin/package location: ~/.local/share/nvim/site/pack/git-plugins/start | |
set runtimepath^=~/.vim runtimepath+=~/.vim/after | |
let &packpath = &runtimepath | |
let g:python3_host_prog='/usr/local/bin/python3' | |
" let g:python_host_prog='/usr/bin/python2' | |
" let g:GPGExecutable = 'gpg2 --trust-model auto' | |
let mapleader = "," | |
scriptencoding utf-8 | |
" ==================================================================== " | |
" === Vim-Plug === " | |
" ==================================================================== " | |
" Automatically install vim-plug | |
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 --sync | source $MYVIMRC | |
endif | |
" call plug#begin('~/.vim/plugged') | |
call plug#begin('~/.local/share/nvim/site/pack/git-plugins/start') | |
"" Make sure you use single quotes | |
Plug 'meain/vim-printer' | |
Plug 'https://github.com/jamessan/vim-gnupg.git' | |
Plug 'https://github.com/jiangmiao/auto-pairs.git' | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
Plug 'junegunn/fzf.vim' | |
Plug 'kkoomen/vim-doge' | |
Plug 'https://github.com/kshenoy/vim-signature.git' | |
Plug 'https://github.com/lilydjwg/colorizer.git' | |
Plug 'https://github.com/ludovicchabant/vim-gutentags.git' | |
Plug 'https://github.com/luochen1990/rainbow.git' | |
Plug 'https://github.com/majutsushi/tagbar.git' | |
Plug 'https://github.com/mbbill/undotree.git' | |
Plug 'https://github.com/mileszs/ack.vim.git' | |
Plug 'https://github.com/ntpeters/vim-better-whitespace.git' | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
Plug 'prettier/vim-prettier', { 'do': 'yarn install' } | |
Plug 'https://github.com/psliwka/vim-smoothie' | |
Plug 'https://github.com/Shougo/deoplete.nvim.git' | |
Plug 'https://github.com/Shougo/neomru.vim.git' | |
Plug 'https://github.com/Shougo/neosnippet.vim.git' | |
Plug 'https://github.com/Shougo/neosnippet-snippets.git' | |
Plug 'styled-components/vim-styled-components', { 'branch': 'main' } " Syntax highlighting for styled-components | |
Plug 'https://github.com/terryma/vim-multiple-cursors.git' | |
Plug 'https://github.com/tpope/vim-commentary' | |
Plug 'https://github.com/tpope/vim-fugitive.git' | |
Plug 'https://github.com/tpope/vim-surround.git' | |
Plug 'https://github.com/vim-airline/vim-airline.git' | |
Plug 'https://github.com/vim-airline/vim-airline-themes.git' | |
Plug 'mhinz/vim-signify' " git changes in the gutter | |
Plug 'mhinz/vim-startify' " Start-up screen for vim | |
Plug 'https://github.com/xuhdev/SingleCompile.git' | |
Plug 'https://github.com/ryanoasis/vim-devicons.git' "devicons needs to load after most other things so leave it here | |
call plug#end() | |
" ==================================================================== " | |
" === UI OPTIONS === " | |
" ==================================================================== " | |
" Enable true color support | |
set termguicolors | |
let $NVIM_TUI_ENABLE_TRUE_COLOR=1 | |
" Add custom highlights in method that is executed every time a | |
" colorscheme is sourced. This must appear before any colorscheme is sourced. | |
" See https://gist.github.com/romainl/379904f91fa40533175dfaec4c833f2f for details. | |
function! MyHighlights() abort | |
" Hightlight trailing whitespace | |
highlight Trail ctermbg=red guibg=red | |
call matchadd('Trail', '\s\+$', 100) | |
endfunction | |
augroup MyColors | |
autocmd! | |
autocmd ColorScheme * call MyHighlights() | |
augroup END | |
set background=dark | |
try | |
"colorscheme doodle | |
colorscheme gruvbox | |
catch | |
colorscheme obsidian | |
endtry | |
highlight Comment cterm=italic | |
highlight String cterm=italic | |
" Set preview window to appear at bottom | |
set splitbelow | |
" Don't dispay mode in command line (airilne already shows it) | |
set noshowmode | |
" Start scrolling 3 lines before the horizontal window border | |
set scrolloff=3 | |
" coc.nvim color changes | |
hi! link CocErrorSign WarningMsg | |
hi! link CocWarningSign Number | |
hi! link CocInfoSign Type | |
" Make background transparent for many things | |
hi! Normal ctermbg=NONE guibg=NONE | |
hi! NonText ctermbg=NONE guibg=NONE | |
hi! LineNr ctermfg=NONE guibg=NONE | |
hi! SignColumn ctermfg=NONE guibg=NONE | |
hi! StatusLine guifg=#16252b guibg=#6699CC | |
hi! StatusLineNC guifg=#16252b guibg=#16252b | |
" ==================================================================== " | |
" === EDITING OPTIONS === " | |
" ==================================================================== " | |
set autoread " Automatically read changes in files | |
set backspace=start,eol,indent " Allow backspace in insert mode | |
set clipboard=unnamed " You can now cmd+c in one application and p it in vim, | |
" or dd in one vim instance and p the line in another. | |
set directory^=$HOME/.vim/swapfiles// " Make swapfiles be kept in a central location to avoid polluting file system | |
let g:mapleader=',' " Remap leader key to , | |
set showmatch " Show matching brackets/parenthesis | |
set number " Enable line numbers | |
set numberwidth=4 | |
set relativenumber " Relative line numbers | |
" set noshowcmd " Don't show last command | |
set laststatus=2 " Show status line | |
set hidden " Hides buffers instead of closing them | |
" Allow buffer switching without saving; | |
" hidden buffers will not be saved if you execute :q!" | |
" " copy and paste to from system clipboard | |
" vmap <leader>y "+y | |
" " vmap <leader>d "+d | |
" nmap <leader>p "+p | |
" nmap <leader>P "+P | |
" vmap <leader>p "+p | |
" vmap <leader>P "+P | |
""""""""""""""""""""""""""""""""""" | |
" Easier split navigations | |
" Create hotkeys to move up and down between windows after opening a second using split (sp). | |
nnoremap <C-J> <C-W><C-J> | |
nnoremap <C-K> <C-W><C-K> | |
nnoremap <C-L> <C-W><C-L> | |
nnoremap <C-H> <C-W><C-H> | |
" === TAB/Space settings === " | |
set expandtab " Insert spaces when TAB is pressed. | |
set softtabstop=2 " Change number of spaces that a <Tab> counts for during editing ops | |
set shiftwidth=2 " Indentation amount for < and > commands. | |
set nocursorline " Don't highlight current cursor line | |
set noruler " Disable line/column number in status line | |
" Shows up in preview window when airline is disabled if not | |
set cmdheight=1 " Only one line for command line | |
set textwidth=79 " Set number of columns before word wrap | |
" === Completion Settings === " | |
set shortmess+=c " Don't give completion messages like 'match 1 of 2' or 'The only match' | |
packloadall " Load all plugins now. | |
" Plugins need to be added to runtimepath before helptags can be generated. | |
silent! helptags ALL " Load all of the helptags now, after plugins have been loaded. | |
" All messages and errors will be ignored. | |
""""""""""""""""""""""""""""""""""" | |
" For use with https://github.com/mileszs/ack.vim | |
if executable('ag') | |
"let g:ackprg = 'ag --vimgrep' | |
let g:ackprg = 'ag --nogroup --column --ignore node_modules' | |
endif | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" Treat all *.svelte files as HTML | |
au! BufNewFile,BufRead *.svelte set ft=html | |
""""""""""""""""""""""""""""""""""" | |
" ==================================================================== " | |
" === FZF SETUP === " | |
" ==================================================================== " | |
" Mapping selecting mappings | |
nmap <leader><tab> <plug>(fzf-maps-n) | |
xmap <leader><tab> <plug>(fzf-maps-x) | |
omap <leader><tab> <plug>(fzf-maps-o) | |
" Insert mode completion | |
imap <c-x><c-k> <plug>(fzf-complete-word) | |
imap <c-x><c-f> <plug>(fzf-complete-path) | |
imap <c-x><c-j> <plug>(fzf-complete-file-ag) | |
imap <c-x><c-l> <plug>(fzf-complete-line) | |
" Advanced customization using autoload functions | |
inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'left': '15%'}) | |
"search all git tracked files | |
nnoremap <leader>f :GFiles<cr> | |
"search all files | |
nnoremap <leader>F :Files<cr> | |
"search open buffers | |
nmap <leader>b :Buffers<cr> | |
"search buffer history | |
nmap <leader>h :History<cr> | |
"search for tags in current buffer, does not require a tags file | |
nmap <leader>t :BTags<cr> | |
"search for tags across project, use with gutentags | |
nmap <leader>T :Tags<cr> | |
"search for lines in current buffer | |
nmap <leader>l :BLines<cr> | |
"search for lines in loaded buffers | |
nmap <leader>L :Lines<cr> | |
"search for marked lines | |
nmap <leader>' :Marks<cr> | |
"search the project, use with Tab, ALT-A for all, and enter | |
nmap <leader>a :Ag<Space> | |
"search Vim help files | |
nmap <leader>H :Helptags!<cr> | |
"search defined commands | |
nmap <leader>C :Commands<cr> | |
"search through :command history | |
nmap <leader>: :History:<cr> | |
"search through /search history | |
nmap <leader>/ :History/<cr> | |
"search key mappings | |
nmap <leader>M :Maps<cr> | |
"search filetype syntaxes, then hit enter to set that syntax on current buffer | |
nmap <leader>s :Filetypes<cr> | |
"" ==================================================================== " | |
" === COC SETUP === " | |
" ==================================================================== " | |
nmap <silent> <leader>dd <Plug>(coc-definition) | |
nmap <silent> <leader>dr <Plug>(coc-references) | |
nmap <silent> <leader>dj <Plug>(coc-implementation) | |
nmap <silent> <leader>re <Plug>(coc-rename) | |
let g:coc_global_extensions = [ | |
\ 'coc-tsserver', | |
\ 'coc-explorer', | |
\ 'coc-html', | |
\ 'coc-json', | |
\ 'coc-lists', | |
\ 'coc-css', | |
\ 'coc-highlight', | |
\ 'coc-stylelintplus', | |
\ 'coc-snippets' | |
\ ] | |
autocmd CursorHold * silent call CocActionAsync('highlight') | |
nmap ge :CocCommand explorer<CR> | |
" use <tab> for trigger completion and navigate to 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() | |
"Close preview window when completion is done. | |
autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif | |
set updatetime=300 " You will have bad experience for diagnostic messages when it's default 4000. | |
set shortmess+=c " don't give |ins-completion-menu| messages. | |
set signcolumn=yes " always show signcolumns | |
" Use tab for trigger completion with characters ahead and navigate. | |
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin. | |
inoremap <silent><expr> <TAB> | |
\ pumvisible() ? "\<C-n>" : | |
\ <SID>check_back_space() ? "\<TAB>" : | |
\ coc#refresh() | |
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" | |
" ==================================================================== " | |
" === NeoSnippet SETUP [needs deoplete] === " | |
" ==================================================================== " | |
" Use deoplete. | |
let g:deoplete#enable_at_startup = 1 | |
" Map <C-k> as shortcut to activate snippet if available | |
imap <C-l> <Plug>(neosnippet_expand_or_jump) | |
smap <C-l> <Plug>(neosnippet_expand_or_jump) | |
xmap <C-l> <Plug>(neosnippet_expand_target) | |
" Load custom snippets from snippets folder | |
let g:neosnippet#snippets_directory='~/.config/nvim/snippets' | |
" Enable snipMate compatibility feature. | |
let g:neosnippet#enable_snipmate_compatibility = 1 | |
" Hide conceal markers | |
let g:neosnippet#enable_conceal_markers = 0 | |
" For conceal markers. | |
" if has('conceal') | |
" set conceallevel=2 | |
" endif | |
" ==================================================================== " | |
" === Airline SETUP === " | |
" ==================================================================== " | |
try | |
" Enable extensions | |
" If you enable this, it kills the buffer bar at the top | |
"""""" let g:airline_extensions = ['branch', 'hunks', 'coc'] | |
" Update section z to just have line number | |
" let g:airline_section_z = airline#section#create(['linenr']) | |
" Do not draw separators for empty sections (only for the active window) > | |
let g:airline_skip_empty_sections = 1 | |
" Custom setup that removes filetype/whitespace from default vim airline bar | |
let g:airline#extensions#default#layout = [['a', 'b', 'c'], ['x', 'z', 'warning', 'error']] | |
let airline#extensions#coc#stl_format_err = '%E{[%e(#%fe)]}' | |
let airline#extensions#coc#stl_format_warn = '%W{[%w(#%fw)]}' | |
" Configure error/warning section to use coc.nvim | |
let g:airline_section_error = '%{airline#util#wrap(airline#extensions#coc#get_error(),0)}' | |
let g:airline_section_warning = '%{airline#util#wrap(airline#extensions#coc#get_warning(),0)}' | |
" Hide the Nerdtree status line to avoid clutter | |
let g:NERDTreeStatusline = '' | |
" set statusline=%t\ %y\ format:\ %{&ff};\ [%c,%l]%{fugitive#statusline()} | |
" Disable vim-airline in preview mode | |
let g:airline_exclude_preview = 1 | |
" Enable powerline fonts | |
let g:airline_powerline_fonts = 1 | |
let g:airline_symbols_ascii = 1 | |
let g:airline_skip_empty_sections = 1 | |
" Enable caching of syntax highlighting groups | |
let g:airline_highlighting_cache = 1 | |
" Define custom airline symbols | |
if !exists('g:airline_symbols') | |
let g:airline_symbols = {} | |
endif | |
" unicode symbols | |
let g:airline_left_alt_sep = '❮' | |
let g:airline_right_alt_sep = '❯' | |
let g:airline_right_sep = '▶' | |
let g:airline_left_sep = '◀' | |
let g:airline_symbols.crypt = '🔒' | |
let g:airline_symbols.spell = 'Ꞩ' | |
let g:airline_symbols.branch = '⎇ ' | |
let g:airline_symbols.whitespace = 'Ξ ' | |
let g:airline_symbols.maxlinenr = '' | |
" Don't show git changes to current file in airline | |
" let g:airline#extensions#hunks#enabled=0 | |
let g:airline#extensions#wordcount#filetypes = ['asciidoc', 'help', 'mail', 'markdown', 'org', 'rst', 'tex', 'text'] | |
let g:airline#extensions#tagbar#enabled = 1 | |
let g:airline#extensions#branch#enabled = 1 | |
let g:airline#extensions#keymap#enabled = 1 | |
let g:airline#extensions#quickfix#quickfix_text = 'Quickfix' | |
let g:airline#extensions#tabline#enabled = 1 | |
let g:airline#extensions#tabline#buffer_nr_show = 1 | |
let g:airline#extensions#tabline#tab_nr_type = 2 " splits and tab number | |
let g:airline#extensions#tabline#fnamemod = ':t' " show just the filename | |
let g:airline#extensions#tabline#formatter = 'unique_tail' " Smartly uniquify buffers names with similar filename, suppressing common parts of paths. | |
catch | |
echo 'Airline not installed. Run `git clone https://github.com/vim-airline/vim-airline.git`' | |
endtry | |
" === end Vim airline === === === === === === === ===" | |
""""""""""""""""""""""""""""""""""" | |
" gutentags | |
" | |
" set ctags | |
set tags=./.tags;,.tags | |
let g:gutentags_project_root = ['.root', '.svn', '.git', '.project', 'package.json'] | |
let g:gutentags_ctags_tagfile = '.tags' | |
let g:gutentags_ctags_exclude = [ '*.phar', '*.ini', '*.rst', '*.md', | |
\ '*var/cache*', '*var/log*', '*var*', '*node_modules*', '*dist*'] | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" rainbow | |
" https://github.com/luochen1990/rainbow | |
let g:rainbow_active = 0 "set to 0 if you want to enable it later via :RainbowToggle | |
autocmd BufEnter *.{js,jsx,html,json,java,py,ts,tsx} :RainbowToggleOn | |
autocmd BufLeave *.{js,jsx,html,json,java,py,ts,tsx} :RainbowToggleOff | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" For use with vim-better-whitespace | |
" https://github.com/ntpeters/vim-better-whitespace | |
" autocmd FileType javascript,c,cpp,java,html,ruby autocmd BufEnter <buffer> EnableStripWhitespaceOnSave | |
nnoremap <leader>st :StripWhitespace<cr> | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" Quote a word consisting of letters from iskeyword. | |
nnoremap <silent> qd :call Quote('"')<CR> | |
nnoremap <silent> qs :call Quote("'")<CR> | |
nnoremap <silent> qu :call UnQuote()<CR> | |
function! Quote(quote) | |
normal mz | |
exe 's/\(\k*\%#\k*\)/' . a:quote . '\1' . a:quote . '/' | |
normal `zl | |
endfunction | |
function! UnQuote() | |
normal mz | |
exe 's/["' . "'" . ']\(\k*\%#\k*\)[' . "'" . '"]/\1/' | |
normal `z | |
endfunction | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" signify [like gitgutter] | |
" https://github.com/mhinz/vim-signify/ | |
let g:signify_vcs_list = ['git'] | |
let g:signify_realtime = 1 | |
let g:signify_line_highlight = 0 | |
nmap <Leader>sg :SignifyToggle<CR> | |
nmap <Leader>sh :SignifyToggleHighlight<CR> | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" Use for tagbar | |
nmap <F8> :TagbarToggle<CR> | |
nmap <Leader>tb :TagbarToggle<CR> | |
let g:tagbar_compact = 0 | |
let g:tagbar_autopreview = 0 | |
let g:tagbar_previewwin_pos = "" | |
let g:tagbar_width = 30 | |
let g:tagbar_sort = 1 | |
let g:tagbar_show_linenumbers = 1 | |
" autocmd FileType c,cpp,javascript,JavaScript,js,py,py3,php,ruby nested :TagbarOpen | |
let g:tagbar_type_css = { | |
\ 'ctagstype' : 'Css', | |
\ 'kinds' : [ | |
\ 'c:classes', | |
\ 's:selectors', | |
\ 'i:identities' | |
\ ] | |
\ } | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" undotree | |
" https://github.com/mbbill/undotree | |
" nnoremap <F5> :UndotreeToggle<cr> | |
nmap <Leader>un :UndotreeToggle<cr> | |
let g:undotree_SetFocusWhenToggle = 1 | |
let g:undotree_WindowLayout = 2 | |
if has("persistent_undo") | |
set undodir=~/.undodir/ | |
set undofile | |
endif | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" for use with devicons | |
" set guifont=DroidSansMono\ Nerd\ Font\ Book\ 11 | |
set guifont=DejaVuSansMonoForPowerline\ Nerd\ Font\ Book\ 12 | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" colorizer | |
" https://github.com/lilydjwg/colorizer.git | |
let g:colorizer_maxlines = 1000 | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" vim-doge for documentation | |
" https://github.com/kkoomen/vim-doge | |
let g:doge_mapping = '<Leader>d' | |
""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""" | |
" vim-styled-components | |
" https://github.com/styled-components/vim-styled-components | |
autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart | |
autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear | |
"""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" Turn this on for SingleCompile | |
filetype plugin on | |
nmap <C-b> :SCCompile<cr> | |
call SingleCompile#SetPriority('javascript', 'node.js', 10) | |
call SingleCompile#SetPriority('javascript', 'js', 20) | |
call SingleCompile#SetPriority('javascript', 'gjs', 30) | |
let g:SingleCompile_quickfixwindowposition = 'horizontal' | |
"let g:SingleCompile_showquickfixiferror = 1 "this opens a split below the code that remains open until manually closed | |
"let g:SingleCompile_showresultafterrun = 1 "this opens a split below the code that remains open until manually closed | |
""""""""""""""""""""""""""""""""""" | |
""""""""""""""""""""""""""""""""""" | |
" prettier | |
" https://github.com/prettier/vim-prettier | |
" | |
" When running at every change you may want to disable quickfix | |
let g:prettier#quickfix_enabled = 0 | |
let g:prettier#autoformat = 0 | |
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync | |
""""""""""""""""""""""""""""""""""" | |
let g:vim_printer_items = { | |
\ 'javascript': 'console.log("Log - {$}:", {$})', | |
\ 'javascript.jsx': 'console.log("Log - {$}:", {$})', | |
\ 'JavaScript': 'console.log("Log - {$}:", {$})', | |
\ 'Javascript': 'console.log("Log - {$}:", {$})', | |
\ 'js': 'console.log("Log - {$}:", {$})', | |
\ } | |
let g:vim_printer_print_below_keybinding = '<leader>c' | |
" end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment