Skip to content

Instantly share code, notes, and snippets.

@mstaicu
Last active January 14, 2021 12:38
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 mstaicu/390997273d6d3e3f2f6c9cc452258f82 to your computer and use it in GitHub Desktop.
Save mstaicu/390997273d6d3e3f2f6c9cc452258f82 to your computer and use it in GitHub Desktop.
Neovim draft configuration file
"Variables {{{
let mapleader=","
" }}}
" Globals {{{
syntax enable
set fileencoding=utf-8
set listchars=space:· " show whitespaces as dots
set list
set noswapfile
" :checkhealth pointed out that neovim cannot find the Python 2 binary
" let g:python_host_prog = '/usr/bin/python'
" forces vim to rescan the entire buffer, due to highlighting getting out of sync for large files, when I enter a JavaScript or TypeScript buffer, and disable it when I leave
autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart
autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear
" }}}
" Space and tabs {{{
set tabstop=2 " how many columns a tab counts for
set softtabstop=2 " set softtabstop to control how many columns vim uses when you hit Tab in insert mode
set shiftwidth=2 " set shiftwidth to control how many columns text is indented with the reindent operations (<< and >>) and automatic C-style indentation
set expandtab " when expandtab is set, hitting Tab in insert mode will produce the appropriate number of spaces
" }}}
" UI layout {{{
set number " show line numbers
set cursorline " highlight current line
" }}}
" Leader key mappings {{{
" stop the highlighting for the 'hlsearch' option
nnoremap <silent> <leader><space> :noh<CR>
" }}}
" Key bindings {{{
"
" do not skip lines that wrap
nnoremap j gj
nnoremap k gk
" move to beginning/end of line
nnoremap B ^
nnoremap E $
" Split panes {{{
set splitbelow
set splitright
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" }}}
" Vim Plug {{{
call plug#begin()
" color theme
Plug 'morhetz/gruvbox'
" airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" syntax highlight
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
Plug 'peitalin/vim-jsx-typescript'
Plug 'styled-components/vim-styled-components', { 'branch': 'main' }
Plug 'jparise/vim-graphql'
Plug 'neoclide/jsonc.vim'
" mighty finder
Plug 'ctrlpvim/ctrlp.vim'
"
call plug#end()
" }}}
" ctrlp {{{
if executable('rg')
set grepprg=rg\ --color=never
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
endif
" }}}
" coc {{{
let g:coc_global_extensions = ['coc-git']
" install eslint, prettier, typescript only if the project has those dependencies
if isdirectory('./node_modules') && isdirectory('./node_modules/prettier')
let g:coc_global_extensions += ['coc-prettier']
endif
if isdirectory('./node_modules') && isdirectory('./node_modules/eslint')
let g:coc_global_extensions += ['coc-eslint']
endif
if isdirectory('./node_modules') && isdirectory('./node_modules/typescript')
let g:coc_global_extensions += ['coc-tsserver']
endif
" set <lead> + p to format the current buffer using prettier
nnoremap <silent> <leader>p :call CocAction('runCommand', 'prettier.formatFile')<CR>
" format current buffer using :Prettier in command mode
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" map following keys to coc commands
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gr <Plug>(coc-references)
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" show symbol documentation with shift + k
nnoremap <silent> K :call <SID>show_hover_doc()<CR>
function! ShowDocIfNoDiagnostic(timer_id)
if (coc#float#has_float() == 0)
silent call CocActionAsync('doHover')
endif
endfunction
function! s:show_hover_doc()
call timer_start(0, 'ShowDocIfNoDiagnostic')
endfunction
" }}}
" airline {{{
let g:airline_theme = 'gruvbox'
" add git blame info to airline statusline section C
" in order for coc_git_blame variable to be populated, you need to set git.addGBlameToBufferVar": true in coc-settings.json
let g:airline_section_c = "%{get(b:,'coc_git_blame','')}"
" }}}
" Color and theme {{{
set termguicolors
colorscheme gruvbox
" }}}
" Conditionals {{{
"" Yank to system clipboard by default
if has("clipboard")
set clipboard=unnamed " copy to the system clipboard
if has("unnamedplus") " X11 support
set clipboard+=unnamedplus
endif
endif
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment