Skip to content

Instantly share code, notes, and snippets.

@banjerluke
Created May 1, 2021 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banjerluke/021c3d91537af8fb1c68d1e909f41b8c to your computer and use it in GitHub Desktop.
Save banjerluke/021c3d91537af8fb1c68d1e909f41b8c to your computer and use it in GitHub Desktop.
Luke's WIP (neo)vim config for Meteor development
{
"suggest.maxCompleteItemCount": 20,
"eslint.format.enable": true,
"coc.preferences.formatOnSaveFiletypes": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"tsserver.formatOnType": true,
"typescript.preferences.importModuleSpecifier": "non-relative",
"javascript.preferences.importModuleSpecifier": "non-relative",
"coc.preferences.formatOnType": true
}
" vim: fdm=marker foldenable foldmarker={{{,}}}
" {{{ Defaults in NeoVim
" Neovim has set these as default
if !has('nvim')
set nocompatible
syntax on " Syntax highlighting
filetype plugin indent on " Automatically detect file types
set autoindent " Indent at the same level of the previous line
set autoread " Automatically read a file changed outside of vim
set backspace=indent,eol,start " Backspace for dummies
set complete-=i " Exclude files completion
set display=lastline " Show as much as possible of the last line
set encoding=utf-8 " Set default encoding
set history=10000 " Maximum history record
set hlsearch " Highlight search terms
set incsearch " Find as you type search
set laststatus=2 " Always show status line
set mouse=a " Automatically enable mouse usage
set smarttab " Smart tab
set ttyfast " Faster redrawing
set viminfo+=! " Viminfo include !
set wildmenu " Show list instead of just completing
set ttymouse=xterm2
endif
" }}}
" {{{ Plugin initialization
" Ensure vim-plug is installed
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/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()
" Which-Key: so I can remember all these darn shortcuts!
Plug 'liuchengxu/vim-which-key', { 'on': ['WhichKey', 'WhichKey!'] }
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
" make vim-commentary and vim-surround work with .
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
" Better netrw file browsing
Plug 'tpope/vim-vinegar'
Plug 'justinmk/vim-sneak'
Plug 'easymotion/vim-easymotion'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" snippets
Plug 'SirVer/ultisnips'
" UndoTree
Plug 'mbbill/undotree'
" Tabular, for lining up text
Plug 'godlygeek/tabular'
Plug 'itchyny/lightline.vim'
Plug 'sinetoami/lightline-hunks'
Plug 'crusoexia/vim-monokai'
" Polyglot for all syntaxes
Plug 'sheerun/vim-polyglot'
" Highlight trailing whitespace
Plug 'ntpeters/vim-better-whitespace'
Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'} " this is for auto complete, prettier and tslinting
"Plug 'ludovicchabant/vim-gutentags'
" Load all plugins defined above
call plug#end()
" }}}
" Remap leader key to spacebar
nnoremap <SPACE> <Nop>
let g:mapleader = "\<Space>"
" {{{ which-key init
" register the descriptions when using on-demand loading
autocmd! User vim-which-key call which_key#register('<Space>', 'g:which_key_map')
nnoremap <silent> <leader> :<c-u>WhichKey '<Space>'<CR>
vnoremap <silent> <leader> :<c-u>WhichKeyVisual '<Space>'<CR>
let g:which_key_map = {}
" hide statusline while whick-key is visible
autocmd! FileType which_key
autocmd FileType which_key set laststatus=0 noshowmode noruler
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
" }}}
" {{{ Colors and syntax
set termguicolors
let g:monokai_term_italic = 1
let g:monokai_gui_italic = 1
autocmd BufRead,BufNewFile *.html setfiletype handlebars
"autocmd BufRead,BufNewFile *.js setfiletype typescript
" }}}
" {{{ Lightline status bar
let g:lightline = {
\ 'colorscheme': 'material',
\ }
let g:lightline.component_function = {
\ 'lightline_hunks': 'lightline#hunks#composer',
\ }
let g:lightline.active = {
\ 'left': [ [ 'mode', 'paste', 'lightline_hunks' ],
\ [ 'readonly', 'filename', 'modified' ] ],
\ 'right': [ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype' ] ] }
" no need for '-- INSERT --' with lightline
set noshowmode
highlight clear SignColumn
" }}}
" {{{ EasyMotion bindings
let g:which_key_map[' '] = { 'name': '+EasyMotion' }
map <leader><leader>w <Plug>(easymotion-w)
let g:which_key_map[' '].w = 'word'
map <leader><leader>W <Plug>(easymotion-W)
let g:which_key_map[' '].W = 'WORD'
map <leader><leader>b <Plug>(easymotion-b)
let g:which_key_map[' '].b = 'back-word'
map <leader><leader>B <Plug>(easymotion-B)
let g:which_key_map[' '].B = 'back-WORD'
map <leader><leader>e <Plug>(easymotion-e)
let g:which_key_map[' '].e = 'end-word'
map <leader><leader>E <Plug>(easymotion-E)
let g:which_key_map[' '].E = 'end-WORD'
map <leader><leader>n <Plug>(easymotion-n)
let g:which_key_map[' '].n = 'next result'
map <leader><leader>N <Plug>(easymotion-N)
let g:which_key_map[' '].N = 'previous result'
map <leader><leader>W <Plug>(easymotion-W)
let g:which_key_map[' '].W = 'Word'
nmap <leader><leader>s <Plug>(easymotion-overwin-sn)
xmap <leader><leader>s <Plug>(easymotion-overwin-sn)
omap <leader><leader>z <Plug>(easymotion-overwin-sn)
let g:which_key_map[' '].s = 'sneak'
map <Leader><Leader>j <Plug>(easymotion-j)
map <Leader><Leader>k <Plug>(easymotion-k)
let g:which_key_map[' '].j = 'lines below'
let g:which_key_map[' '].k = 'lines above'
map <Leader><Leader><Leader> <Plug>(easymotion-repeat)
let g:which_key_map[' '][' '] = 'repeat motion'
" }}}
" {{{ FZF Bindings
nnoremap <leader>j :<C-u>Files<CR>
let g:which_key_map.j = 'Jump to file'
nnoremap <leader>f :<C-u>Rg<SPACE>
let g:which_key_map.f = 'Find in files'
let g:which_key_map.b = { 'name': '+Buffer' }
nnoremap <leader>bl :<C-u>BLines<CR>
let g:which_key_map.b.l = 'Filter lines'
nnoremap <leader>bc :<C-u>BCommits<CR>
let g:which_key_map.b.c = 'See commits'
nnoremap <leader>bb :<C-u>Buffers<CR>
let g:which_key_map.b.b = 'Switch buffers'
nnoremap <leader>bn :<C-u>bnext<CR>
let g:which_key_map.b.n = 'Next buffer'
nnoremap <leader>bp :<C-u>bprev<CR>
let g:which_key_map.b.p = 'Previous buffer'
nnoremap <leader>w :<C-u>Windows<CR>
let g:which_key_map.w = 'Switch windows'
nnoremap <leader>h :<c-u>History<cr>
let g:which_key_map.h = 'History'
nnoremap <leader>m :<C-u>Marks<CR>
let g:which_key_map.m = 'Marks'
" }}}
" {{{ CoC / autocomplete setup
let g:coc_global_extensions = ['coc-tsserver', 'coc-css', 'coc-html', 'coc-json', 'coc-snippets']
" Add CoC Prettier if prettier is installed
if isdirectory('./node_modules') && isdirectory('./node_modules/prettier')
let g:coc_global_extensions += ['coc-prettier']
endif
" Add CoC ESLint if ESLint is installed
if isdirectory('./node_modules') && isdirectory('./node_modules/eslint')
let g:coc_global_extensions += ['coc-eslint']
endif
" Make Ctrl-J/K navigate autocomplete and enter select
let g:coc_snippet_next = ''
let g:coc_snippet_prev = ''
inoremap <expr> <c-j>
\ pumvisible() ? "\<c-n>" :
\ coc#jumpable() ? "\<c-r>=coc#rpc#request('snippetNext', [])<cr>" :
\ "\<c-j>"
inoremap <expr> <c-k>
\ pumvisible() ? "\<c-p>" :
\ coc#jumpable() ? "\<c-r>=coc#rpc#request('snippetPrev', [])<cr>" :
\ "\<c-k>"
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" }}}
" {{{ CoC bindings
" Map function and class text objects with CoC
" NOTE: Requires 'textDocument.documentSymbol' support from the language server
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>qa <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Format
nmap <leader>= :CocCommand prettier.formatFile<CR>
let g:which_key_map['='] = 'format file'
" Symbol renaming.
nmap <F2> <Plug>(coc-rename)
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
"nmap <silent> <C-s> <Plug>(coc-range-select)
"xmap <silent> <C-s> <Plug>(coc-range-select)
" }}}
" {{{ Custom command bindings
nnoremap <leader>n :noh<CR>
let g:which_key_map.n = 'clear highlight'
" vertical split by pressing v twice
nnoremap <silent> vv <c-w>v
" Exit terminal with ESC
if has("nvim")
au TermOpen * tnoremap <buffer> <Esc> <c-\><c-n>
au FileType fzf tunmap <buffer> <Esc>
endif
nnoremap <leader>r :<C-u>registers<CR>
let g:which_key_map.r = ':registers'
" Easy quickfix navigation
nnoremap <C-n> :cn<CR>
nnoremap <C-p> :cp<CR>
" Easier movement between split windows CTRL + {h, j, k, l}
nnoremap <c-h> <c-w>h
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-l> <c-w>l
" Change indent continuously
vmap < <gv
vmap > >gv
" Treat long lines as break lines
nmap j gj
vmap j gj
nmap k gk
vmap k gk
nnoremap <leader>c "+
let g:which_key_map.v = { 'name': '+Vim' }
" Open Vim configuration file for editing
nnoremap <silent><leader>ve :tabedit $MYVIMRC<CR>
" Install plugins
nnoremap <silent><leader>vp :PlugInstall<CR>
" Source Vim configuration file
nnoremap <silent><leader>vs :source $MYVIMRC<CR>
" Faster saving and exiting
"nnoremap <silent><leader>w :w!<CR>
"nnoremap <silent><leader>q :q!<CR>
"nnoremap <silent><leader>x :x<CR>
" Easy saving -- don't yell at me, Ctrl-S is so easy
inoremap <C-s> <ESC>:w<CR>
nnoremap <C-s> :w<CR>
" :W sudo saves the file
" (useful for handling the permission-denied error)
command! W w !sudo tee % > /dev/null
" Open shell in vim
if has('nvim') || has('terminal')
map <silent> <Leader>` :terminal<CR>
else
map <silent> <Leader>` :shell<CR>
endif
" Search for selected text, forwards or backwards.
vnoremap <silent> * :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy/<C-R>=&ic?'\c':'\C'<CR><C-R><C-R>=substitute(
\escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gVzv:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy?<C-R>=&ic?'\c':'\C'<CR><C-R><C-R>=substitute(
\escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gVzv:call setreg('"', old_reg, old_regtype)<CR>
" }}}
" Search down into subfolders and provide tab-completion for things
set path+=**
set ignorecase smartcase
set pastetoggle=<F3>
" Split right/below by default
set splitright
set splitbelow
" Folding
set foldenable
set foldmarker={,}
set foldlevel=0
set foldmethod=marker
" set foldcolumn=3
set foldlevelstart=99
" augroup vimrc
" au BufReadPre * setlocal foldmethod=indent
" au BufWinEnter * if &fdm == 'indent' | setlocal foldmethod=manual | endif
" augroup END
" consider adding Konfekt/FastFold and Konfekt/FoldText
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" for which-key, for example
set timeoutlen=300
" don't complain if leaving an unsaved window
set hidden
" lines to scroll when cursor leaves screen
set scrolljump=10
" Minumum lines to keep above and below cursor
set scrolloff=3
" no line wrapping by default
set nowrap
" automatically save when leaving a buffer -- not sure about this one
set autowrite
" hide mouse while typing
set mousehide
" Enable line numbers
set number relativenumber
:augroup numbertoggle
: autocmd!
: autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
: autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
:augroup END
" Set backups
if has('persistent_undo')
set undofile
set undolevels=3000
set undoreload=10000
endif
"set backupdir=~/.local/share/nvim/backup " Don't put backups in current dir
"set backup
set noswapfile
" 🤷
set mouse=a
" Post-plugin-init setup
colorscheme monokai
" Go to js imports without .js
setlocal suffixesadd+=.js
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"/*": ["./*"]
},
"checkJs": true
},
"exclude": ["node_modules", ".meteor"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment