Skip to content

Instantly share code, notes, and snippets.

@sebastianvera
Last active December 27, 2020 21:46
Show Gist options
  • Save sebastianvera/4946c6e14974701bc57e13a86058962d to your computer and use it in GitHub Desktop.
Save sebastianvera/4946c6e14974701bc57e13a86058962d to your computer and use it in GitHub Desktop.
Vim config
let mapleader = " "
" Install vundle
let shouldInstallBundles = 0
if !filereadable($HOME . "/.config/nvim/autoload/plug.vim")
echo "~≥ Installing vim-plug \n"
silent !curl -fLo $HOME/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
let shouldInstallBundles = 1
endif
" Plugins
call plug#begin('~/.config/nvim/plugged')
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
function! s:show_documentation()
if &filetype == 'vim'
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Create mappings for function text object, requires document symbols feature of languageserver.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-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)
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
nmap <silent> [e <Plug>(coc-diagnostic-prev-error)
nmap <silent> ]e <Plug>(coc-diagnostic-next-error)
nmap <leader>ac <Plug>(coc-codeaction-selected)
xmap <leader>ac <Plug>(coc-codeaction-selected)
nmap <leader>rn <Plug>(coc-rename)
nmap <leader>qf <Plug>(coc-fix-current)
nnoremap <silent> <leader>y :<C-u>CocList -A --normal yank<cr>
nnoremap <silent> K :call <SID>show_documentation()<CR>
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
inoremap <silent><expr> <c-space> coc#refresh()
nmap <leader>qf <Plug>(coc-fix-current)
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
vmap <C-j> <Plug>(coc-snippets-select)
" coc-explorer
let g:coc_explorer_global_presets = {
\ '.vim': {
\ 'root-uri': '~/.vim',
\ },
\ 'tab': {
\ 'position': 'tab',
\ 'quit-on-open': v:true,
\ },
\ 'floating': {
\ 'position': 'floating',
\ 'open-action-strategy': 'sourceWindow',
\ },
\ 'floatingTop': {
\ 'position': 'floating',
\ 'floating-position': 'center-top',
\ 'open-action-strategy': 'sourceWindow',
\ },
\ 'floatingLeftside': {
\ 'position': 'floating',
\ 'floating-position': 'left-center',
\ 'floating-width': 50,
\ 'open-action-strategy': 'sourceWindow',
\ },
\ 'floatingRightside': {
\ 'position': 'floating',
\ 'floating-position': 'right-center',
\ 'floating-width': 50,
\ 'open-action-strategy': 'sourceWindow',
\ },
\ 'simplify': {
\ 'file-child-template': '[selection | clip | 1] [indent][icon | 1] [filename omitCenter 1]'
\ }
\ }
noremap <silent> - :execute 'CocCommand explorer' .
\ ' --toggle' .
\ ' --sources=file+'
\ ' --preset floating'
\ fnamemodify(expand('%:p'), ':p:h')<CR>
" coc-prettier
command! -nargs=0 Prettier :CocCommand prettier.formatFile
noremap <leader>mp :Prettier<CR>
" coc-jest
" Run jest for current project
command! -nargs=0 Jest :call CocAction('runCommand', 'jest.projectTest')
" Run jest for current file
command! -nargs=0 JestCurrent :call CocAction('runCommand', 'jest.fileTest', ['%'])
" Run jest for current test
nnoremap <leader>ts :call CocAction('runCommand', 'jest.singleTest')<CR>
" Run jest for current file
nnoremap <leader>tf :JestCurrent<CR>
" coc-actions
" Remap for do codeAction of selected region
function! s:cocActionsOpenFromSelected(type) abort
execute 'CocCommand actions.open ' . a:type
endfunction
xmap <silent> <leader>ca :<C-u>execute 'CocCommand actions.open ' . visualmode()<CR>
nmap <silent> <leader>ca :<C-u>set operatorfunc=<SID>cocActionsOpenFromSelected<CR>g@
" coc-go
" autocmd BufWritePre *.go :call CocAction('organizeImport')
Plug 'junegunn/vim-easy-align'
" 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)
Plug 'mhinz/vim-startify'
let g:startify_bookmarks = [
\ '~/.zshrc',
\ '~/.config/nvim/init.vim',
\ '~/Code/tk/trendkite-front-end',
\ '~/Code/apipath/ppoker-graphql-react',
\ ]
let g:startify_change_to_dir = 1
let g:startify_skiplist = [
\ 'COMMIT_EDITMSG',
\ ]
let g:startify_list_order = [
\ [' LRU:'],
\ 'files',
\ [' LRU within this dir:'],
\ 'dir',
\ [' Sessions:'],
\ 'sessions',
\ [' Bookmarks:'],
\ 'bookmarks',
\ ]
Plug 'cohama/lexima.vim'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-fugitive'
noremap <leader>gb :Gblame<CR>
Plug 'tpope/vim-markdown'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' }
let g:markdown_fenced_languages = ['css', 'javascript', 'js=javascript', 'typescript', 'ts=typescript', 'json', 'sql']
Plug 'tpope/vim-endwise'
Plug 'airblade/vim-gitgutter'
Plug 'christoomey/vim-tmux-navigator'
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> <c-h> :TmuxNavigateLeft<CR>
nnoremap <silent> <c-j> :TmuxNavigateDown<CR>
nnoremap <silent> <c-k> :TmuxNavigateUp<CR>
nnoremap <silent> <c-l> :TmuxNavigateRight<CR>
Plug 'christoomey/vim-tmux-runner'
let g:VtrUseVtrMaps = 1
let g:VtrGitCdUpOnOpen = 0
let g:VtrPercentage = 30
let g:vtr_filetype_runner_overrides = {
\ 'go': 'go run {file}',
\ 'node': 'node {file}'
\ }
nnoremap <silent> <leader>ap :VtrAttachToPane<CR>
Plug 'jgdavey/tslime.vim'
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
let g:fzf_command_prefix = 'Fzf'
let g:fzf_history_dir = '~/.local/share/fzf-history'
let g:fzf_files_options='--preview-window down:wrap --reverse'
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.9 } }
command! -bang -nargs=? -complete=dir FzfFiles
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview('down:50%', '?'), <bang>0)
command! -bang -nargs=? -complete=buffer FzfBuffers
\ call fzf#vim#buffers(<q-args>, fzf#vim#with_preview({ "placeholder": "{1}", "options": ["-d", "\t"] }, 'up:50%', '?'), <bang>0)
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview('up:60%'),
\ <bang>0)
inoremap <expr> <c-x><c-l> fzf#vim#complete(fzf#wrap({
\ 'prefix': '^.*$',
\ 'source': 'rg -n ^ --color always',
\ 'options': '--ansi --delimiter : --nth 3..',
\ 'reducer': { lines -> join(split(lines[0], ':\zs')[2:], '') }}))
noremap <silent> <c-p> :FzfGitFiles<CR>
nnoremap <leader>p :FzfFiles<cr>
nnoremap <leader>b :FzfBuffers<cr>
nnoremap <silent> <leader>ag :Rg <C-R><C-W><CR>
vnoremap <silent> <leader>ag y:Rg <C-R>"<CR>
" 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)
Plug 'elzr/vim-json', {'for' : 'json'}
let g:vim_json_syntax_conceal = 0
Plug 'ekalinin/Dockerfile.vim', { 'for': ['dockerfile', 'Dockerfile'] }
Plug 'nicholaides/words-to-avoid.vim'
Plug 'chrisbra/Colorizer'
Plug 'pangloss/vim-javascript'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'leafgarland/typescript-vim'
Plug 'jparise/vim-graphql'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
" let g:go_fmt_command = "goimports"
" disable vim-go :GoDef short cut (gd)
" this is handled by LanguageClient [LC]
let g:go_def_mapping_enabled = 0
let g:go_doc_popup_window = 1
let g:go_addtags_transform = 'camelcase'
let g:go_fmt_fail_silently = 1
let g:go_autodetect_gopath = 1
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
let g:go_metalinter_enabled = ['vet', 'golint']
let g:go_imports_mode="gopls"
let g:go_imports_autosave=1
let g:go_highlight_build_constraints = 1
let g:go_highlight_operators = 1
Plug 'editorconfig/editorconfig-vim'
Plug 'othree/html5.vim'
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<S-Tab>'
let g:UltiSnipsEditSplit = 'vertical'
autocmd FileType typescript,typescript.tsx call UltiSnips#AddFiletypes('javascript.typescript')
noremap <leader>sp :UltiSnipsEdit<CR>
Plug 'Shougo/echodoc.vim'
let g:echodoc#enable_at_startup = 1
Plug 'rakr/vim-one'
Plug 'junegunn/limelight.vim'
Plug 'junegunn/goyo.vim'
noremap <leader>f :Goyo<CR>
" Goyo & Limelight
autocmd! User GoyoEnter Limelight
autocmd! User GoyoLeave Limelight!
Plug 'itchyny/lightline.vim'
function! CocCurrentFunction()
return get(b:, 'coc_current_function', '')
endfunction
function! LightlineFugitive()
if &ft !~? 'vimfiler' && exists('*fugitive#head')
let branch = fugitive#head()
if len(branch) < 25
return branch
endif
return branch[:25] . ' ... '
endif
return ''
endfunction
let g:lightline = {
\ 'colorscheme': 'one',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch' ],
\ [ 'cocstatus', 'currentfunction', 'readonly'],
\ ['filename', 'modified' ]
\ ],
\ 'right': [ [ 'lineinfo' ],
\ [ 'filetype' ] ]
\ },
\ 'component_function': {
\ 'cocstatus': 'coc#status',
\ 'currentfunction': 'CocCurrentFunction',
\ 'gitbranch': 'LightlineFugitive',
\ },
\ }
Plug 'rhysd/git-messenger.vim'
let g:git_messenger_include_diff = "current"
Plug 'hashivim/vim-terraform'
let g:terraform_fmt_on_save=1
Plug 'wellle/targets.vim'
Plug 'jxnblk/vim-mdx-js'
call plug#end()
if shouldInstallBundles == 1
echo "~> Installing plugs\n"
:PlugInstall
endif
" Vim Config
filetype plugin indent on
syntax enable
let g:python3_host_prog = '/usr/local/bin/python3'
" General
set ruler
set autowrite
set noswapfile nowritebackup nobackup
set number relativenumber
set history=1000
set ttimeout ttimeoutlen=1 timeoutlen=500
set wildmenu wildmode=list:full
set wildignore=*.o,*.obj,tmp,.git,node_modules,bower_components,.DS_Store,build
set visualbell
set fileformats+=mac
set display+=lastline
set splitright splitbelow
set cursorline
set pumheight=10
set nowrap
set inccommand=split "nosplit
set showcmd
set termguicolors
set cmdheight=1
set updatetime=300
set shortmess+=c
set signcolumn=yes
set nofoldenable
set mouse=a
set noshowmode
" Indendation
set autoindent smarttab expandtab
set shiftround tabstop=2 shiftwidth=2
set pastetoggle=<F2>
" Search
set gdefault
set ignorecase smartcase
set list
set listchars=tab:▸\ ,trail:•,extends:»,precedes:«,nbsp:¬
set scrolloff=1 sidescrolloff=5
" Colors
colorscheme one
set bg=dark
" Mappings
inoremap <C-U> <C-G>u<C-U>
inoremap jk <Esc>
nnoremap <leader><leader> <C-^>
nnoremap <leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
noremap <leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
noremap <leader>so :w<CR> :so ~/.config/nvim/init.vim<CR>
noremap <leader>vi :tabe ~/.config/nvim/init.vim<CR>
noremap <leader>pi :w<CR> :so ~/.config/nvim/init.vim<CR> :PlugInstall<CR>
noremap <leader>pu :PlugUpdate<CR>
noremap <leader>h :nohl<CR>
vnoremap <C-c> "*y
vnoremap // y/\V<C-R>"<CR>
" nmap k gk
" nmap j gj
map Q <Nop>
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
command! Q q
command! Qa qa
" Do not show stupid q: window
map q: :q
if has('persistent_undo')
set undofile
set undodir=~/.config/nvim/tmp/undo//
endif
" Allow project-specific `vimrc`s:
" http://andrew.stwrt.ca/posts/project-specific-vimrc/
set exrc
" Leave paste mode when leaving insert mode
autocmd InsertLeave * set nopaste
" Javascript config files
autocmd BufRead,BufNewFile .eslintrc,.jscsrc,.jshintrc,.babelrc,.tern-project,.prettierrc set ft=json
" Markdown
au BufRead,BufNewFile *.md,*.mdx setlocal textwidth=80
autocmd BufRead,BufNewFile *.md,*.mdx setlocal spell
" Open file on last position
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" Git commits
au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
" Typescript
au BufNewFile,BufRead *.ts setlocal filetype=typescript
au BufNewFile,BufRead *.tsx setlocal filetype=typescript.tsx
" JSON
autocmd FileType json syntax match Comment +\/\/.\+$+
" Remove once my PR gets merged
" set runtimepath^=/Users/sebastianvera/Code/coc-jest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment