Skip to content

Instantly share code, notes, and snippets.

@YanikCeulemans
Last active August 18, 2020 08:08
Show Gist options
  • Save YanikCeulemans/9dacf4bf0756454b0977f239c78333d3 to your computer and use it in GitHub Desktop.
Save YanikCeulemans/9dacf4bf0756454b0977f239c78333d3 to your computer and use it in GitHub Desktop.
NeoVim Configuration
" Forget being compatible with good ol' vi
set nocompatible
" Start vim plugged
" Specify a directory for plugins
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'scrooloose/nerdtree'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'airblade/vim-gitgutter'
Plug 'scrooloose/nerdcommenter'
Plug 'tpope/vim-unimpaired'
Plug 'peterrincker/vim-argumentative'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-sleuth'
Plug 'itchyny/lightline.vim'
" Git wrapper -> g? for info, :help fugitive
Plug 'tpope/vim-fugitive'
" fzf fuzzy find files
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
"
" TS Syntax
Plug 'HerringtonDarkholme/yats.vim'
Plug 'digitaltoad/vim-jade'
Plug 'maxmellon/vim-jsx-pretty'
" Elm
Plug 'andys8/vim-elm-syntax'
" Elixir
Plug 'elixir-lang/vim-elixir'
" Theme
Plug 'rakr/vim-one'
Plug 'ryanoasis/vim-devicons'
" Initialize plugin system
call plug#end()
" End vim plugged
" Theme config
if (has("termguicolors"))
set termguicolors
endif
" set background=light
set background=dark
let g:one_allow_italics = 1
colorscheme one
let g:NERDSpaceDelims = 1
nmap <silent> <C-l> :call NERDTreeToggleInCurDir()<CR>
vmap ++ <plug>NERDCommenterToggle
nmap ++ <plug>NERDCommenterToggle
let g:NERDTreeIgnore = ['^node_modules$']
" Open NERDTree in the directory of the current file (or /home if no file is open)
" nmap <silent> <C-i> :call NERDTreeToggleInCurDir()<cr>
function! NERDTreeToggleInCurDir()
" If NERDTree is open in the current buffer
if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1
NERDTreeClose
elseif &modifiable && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
else
NERDTree
endif
endfunction
set encoding=utf-8
set nowrap
" Map <leader> to `,`
let mapleader=','
set wildignore+=*/tmp/*,*.swp,*.zip,*.exe,*/node_modules/*,*/elm-stuff/*,*/.git/*,*/dist/*
" fzf config start
nnoremap <C-p> :Files<Cr>
nnoremap <C-g> :Rg<Cr>
nnoremap <C-q> :Buffers<Cr>
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --ignore-case --no-heading --color=always --smart-case -g "!node_modules" '.shellescape(<q-args>),
\ 1,
\ fzf#vim#with_preview({'options': '--delimiter : --nth 2..'}), <bang>0)
let g:fzf_buffers_jump = 1
" fzf config end
" Begin COC config
let g:coc_global_extensions = [
\ 'coc-snippets',
\ 'coc-pairs',
\ 'coc-tsserver',
\ 'coc-eslint',
\ 'coc-prettier',
\ 'coc-json',
\ ]
"inoremap <silent><expr> <c-space> coc#refresh()
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
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)
nmap <silent> gsd :vs<CR><Plug>(coc-definition)
nmap <silent> gvd :sp<CR><Plug>(coc-definition)
nmap <leader>ac <Plug>(coc-codeaction)
nmap <silent> <C-t> :CocList symbols<CR>
inoremap <silent><expr> <TAB> pumvisible() ? coc#_select_confirm() : "<TAB>"
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Remap renaming
nmap <F2> <Plug>(coc-rename)
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" Remap for format selected region
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
nmap <leader>af :Format<CR>
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
augroup mygroup
autocmd!
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
command! -nargs=0 Format :call CocAction('format')
" End COC config
" Expand region config
vmap ) <Plug>(expand_region_expand)
vmap ( <Plug>(expand_region_shrink)
" leader cf to copy current buffer file path
nmap <leader>cf :let @" = expand("%")<CR>
" leader t to open a new empty tab
nmap <leader>t :tabnew<CR>
" Reduce update time from 4s to 100ms
set updatetime=100
" Line numbers plz...
set number
set relativenumber
" Tab conf
set tabstop=2 softtabstop=0 expandtab shiftwidth=0 smarttab
" Turn on that syntax highlighting
syntax on
" Why is this not a default
set hidden
" Don't touch my backspace please!
set backspace=indent,eol,start
" Don't update the display while executing macros
set lazyredraw
" At least let yourself know what mode you're in
set showmode
" Always show statusbar
set laststatus=2
set noshowmode
" Lightline config
let g:lightline = {
\ 'colorscheme': 'one',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'projectname', 'shortrelativepath', 'modified' ] ],
\ 'right': [ [ 'percent' ],
\ [ 'lineinfo' ] ]
\ },
\ 'component_function': {
\ 'projectname': 'ProjectName',
\ 'shortrelativepath': 'ShortRelativePath'
\ },
\ 'component': {
\ 'lineinfo': '%3l:%-2v%<'
\ }
\ }
function! ProjectName()
return split(getcwd(), '/')[-1]
endfunction
function! ShortRelativePath()
let cfPath = expand("%")
if strlen(cfPath) > 35
return join(map(split(expand("%:h"), '/'), {_, val -> val[0]}) + [expand("%:t")], "/")
else
return cfPath
endif
endfunction
" Highlight the current line please
set cursorline
" Let's make it easy to edit this file (mnemonic for the key sequence is
" 'e'dit 'v'imrc)
nmap <silent> ,ev :e $MYVIMRC<cr>
"case insensitive search
set ignorecase
set smartcase
"use ',,' as find next quote and append
inoremap ,, <ESC>la
" OO start editing on a new line above the current line
inoremap OA <Esc>O
inoremap OO <Esc>o
" AA append to EoL
inoremap AA <Esc>A
"Exit insert mode
inoremap jj <Esc>
" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
map <space> /
map <c-space> ?
" Map 'S' to erase up untill the start of the line
map S ^C
" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
map N Nzz
map n nzz
" Change pwd to current file directory
nnoremap ,cd :cd %:p:h<CR>
" nnoremap <silent> <C-L> :nohlsearch<CR><C-L>
" use ENTER to clear search highlighting
nnoremap <silent> <CR> :noh<CR>
noremap tt :tab split<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment