Skip to content

Instantly share code, notes, and snippets.

@sebastianvera
Created November 1, 2019 23:36
Show Gist options
  • Save sebastianvera/6ad8a19ef65bd691932de73c67392d23 to your computer and use it in GitHub Desktop.
Save sebastianvera/6ad8a19ef65bd691932de73c67392d23 to your computer and use it in GitHub Desktop.
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' }
Plug 'cohama/lexima.vim'
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'christoomey/vim-tmux-navigator'
Plug 'christoomey/vim-tmux-runner'
Plug 'jgdavey/tslime.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'elzr/vim-json', {'for' : 'json'}
Plug 'ekalinin/Dockerfile.vim', { 'for': ['dockerfile', 'Dockerfile'] }
Plug 'fatih/vim-go', { 'for': 'go' }
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'rakr/vim-one'
Plug 'liuchengxu/eleline.vim'
call plug#end()
if shouldInstallBundles == 1
echo "~> Installing plugs\n"
:PlugInstall
endif
" Vim Config
filetype plugin indent on
syntax enable
" 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=nosplit
set showcmd
set termguicolors
set cmdheight=2
set updatetime=300
set shortmess+=c
set signcolumn=yes
set nofoldenable
set mouse=a
" Indendation
set autoindent smarttab expandtab
set shiftround tabstop=2 shiftwidth=2
" Search
set gdefault
set ignorecase smartcase
set list
set listchars=tab:▸\ ,trail:•,extends:»,precedes:«,nbsp:¬
set scrolloff=1 sidescrolloff=5
colorscheme one
set bg=dark
" Mappings
inoremap <C-U> <C-G>u<C-U>
inoremap jk <Esc>
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>
noremap <Leader>sp :UltiSnipsEdit<CR>
noremap <Leader>gb :Gblame<CR>
vnoremap <C-c> "*y
vnoremap // y/\V<C-R>"<CR>
vnoremap <silent> <Leader>ag y:Rg <C-R>"<CR>
nnoremap <silent> <Leader>ag :Rg <C-R><C-W><CR>
nnoremap <Leader><Leader> <C-^>
" Open new file adjacent to current file
nnoremap <leader>e :e <C-R>=expand("%:p:h") . "/" <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
" 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>
" 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>
" Ultisnips
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<S-Tab>'
let g:UltiSnipsEditSplit = 'vertical'
let g:UltiSnipsSnippetDirectories = ['~/.config/nvim/UltiSnips', 'UltiSnips']
" Fzf
" Global line completion (not just open buffers. ripgrep required.)
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:], '') }}))
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Likewise, Files command with preview window
command! -bang -nargs=? -complete=dir GFiles
\ call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview('right:50%'), <bang>0)
nnoremap <c-p> :GFiles<cr>
nnoremap <leader>p :Files<cr>
nnoremap <leader>b :Buffers<cr>
let g:fzf_history_dir = '~/.local/share/fzf-history'
" Allow project-specific `vimrc`s:
" http://andrew.stwrt.ca/posts/project-specific-vimrc/
set exrc
autocmd BufRead,BufNewFile .eslintrc,.jscsrc,.jshintrc,.babelrc,.tern-project,.prettierrc set ft=json
au BufRead,BufNewFile *.md setlocal textwidth=80
" Leave paste mode when leaving insert mode
autocmd InsertLeave * set nopaste
" json
let g:vim_json_syntax_conceal = 0
if has('persistent_undo')
set undofile
set undodir=~/.config/nvim/tmp/undo//
endif
" Open file on last position
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
"
" FZF
" 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)
" CoC
nnoremap <silent> K :call <SID>show_documentation()<CR>
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 <leader>ac <Plug>(coc-codeaction)
nmap <leader>rn <Plug>(coc-rename)
nmap <leader>qf <Plug>(coc-fix-current)
inoremap <silent><expr> <c-space> coc#refresh()
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
let g:eleline_basic = 1
" Golang
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment