Skip to content

Instantly share code, notes, and snippets.

@ldelelis
Last active Oct 12, 2021
Embed
What would you like to do?
" Configure the editor itself
set background=dark
set title
set ignorecase
set smartcase
set wrap
set autoindent
set copyindent
set smartindent
set number
set relativenumber
set noswapfile
set noshowmode
set equalalways
set lazyredraw
set splitbelow
set updatetime=300
set shortmess+=c
if has("nvim-0.5.0") || has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
" This is only necessary if you use "set termguicolors".
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
" fixes glitch? in colors when using vim with tmux
set t_Co=256
set termguicolors
syntax on
filetype on
filetype plugin on
filetype plugin indent on
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType c setlocal ts=4 sts=4 sw=4 expandtab
autocmd FileType cpp setlocal ts=4 sts=4 sw=4 expandtab
autocmd FileType javascript setlocal ts=4 sts=4 sw=4 expandtab
autocmd FileType typescript setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType Jenkinsfile setlocal ts=4 sts=4 sw=4 expandtab
au BufNewFile,BufRead /*.rasi setf css
au BufNewFile,BufRead *.nix set ft=nix
autocmd FileType python let b:coc_root_patterns = ['manage.py']
autocmd BufNewFile,BufRead *.py
\ setlocal tabstop=4 |
\ setlocal softtabstop=4 |
\ setlocal shiftwidth=4 |
\ setlocal textwidth=99 |
\ setlocal expandtab |
\ set fileformat=unix
autocmd FileType sh
\ setlocal tabstop=4 |
\ setlocal softtabstop=4 |
\ setlocal shiftwidth=4 |
\ setlocal expandtab
" Trim trailing whitespace on save
autocmd BufWritePre * %s/\s\+$//e
" Automatically enter insert mode on terminals
autocmd BufEnter term://* startinsert
" Load plugins
call plug#begin()
Plug 'Shougo/defx.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'hashivim/vim-terraform', { 'for': 'terraform' }
Plug 'rust-lang/rust.vim', { 'for': 'rust' }
Plug 'tpope/vim-surround'
Plug 'Yggdroot/indentLine'
Plug 'Raimondi/delimitMate'
Plug 'yuttie/comfortable-motion.vim'
Plug 'ludovicchabant/vim-gutentags'
Plug 'junegunn/fzf', { 'do': './install --bin' }
Plug 'junegunn/fzf.vim'
Plug 'martinda/Jenkinsfile-vim-syntax'
Plug 'SirVer/ultisnips'
Plug 'vim-scripts/indentpython.vim'
Plug 'tpope/vim-repeat'
Plug 'pearofducks/ansible-vim', { 'do': './UltiSnips/generate.sh --style dictionary' }
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'vim-test/vim-test'
call plug#end()
colorscheme dracula
" Set up keybinds
let mapleader = "\<Space>"
let maplocalleader = ","
inoremap jk <esc>
nnoremap H gT
nnoremap L gt
" Disable ex mode
nnoremap Q <nop>
" Handy disable highlight bind
nnoremap <silent> <Leader>h :noh<CR>
" Open a small terminal
nnoremap <silent> <leader>` :10sp term://zsh<CR>
" Improve pane naviation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Quicker pane zoom
" TODO: try to make this a toggle with a single bind
nnoremap <silent> <Leader>f :vertical resize<CR>
nnoremap <silent> <Leader>= <C-w>=
" Navigate between wrapped lines
noremap <silent> k gk
noremap <silent> j gj
noremap <silent> 0 g0
noremap <silent> $ g$
" Search visual mode selection
vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>
" Inline encode/decode base64
vnoremap <silent> <Leader>be y:let @"=system('base64 -w0', @")<CR>gvP
vnoremap <silent> <Leader>bd y:let @"=system('base64 --decode', @")<CR>gvP
" DEFX
map <silent> <leader>e :Defx -show-ignored-files<CR>
call defx#custom#option('_', {
\ 'columns': 'indent:git:icons:filename',
\ 'winwidth': 28,
\ 'split': 'vertical',
\ 'direction': 'topleft',
\ 'show_ignored_files': 0,
\ })
autocmd FileType defx setlocal nornu nonumber
autocmd WinEnter * if &ft == 'defx' && winnr('$') == 1 | q | endif
autocmd TabLeave * if &ft == 'defx' | wincmd w | endif
autocmd FileType defx do WinEnter | call s:defx_my_settings()
function! s:defx_my_settings() abort
nnoremap <silent><buffer><expr> q defx#do_action('quit')
nnoremap <silent><buffer><expr> <CR> defx#do_action('drop')
nnoremap <silent><buffer><expr> N defx#do_action('new_multiple_files')
nnoremap <silent><buffer><expr> o defx#do_action('new_directory')
nnoremap <silent><buffer><expr><nowait> m defx#do_action('move')
nnoremap <silent><buffer><expr><nowait> p defx#do_action('paste')
nnoremap <silent><buffer><expr> l <sid>defx_toggle_tree()
nnoremap <silent><buffer><expr> h defx#do_action('cd', ['..'])
endfunction
function! s:defx_toggle_tree() abort
if defx#is_directory()
return defx#do_action('open_or_close_tree')
endif
return defx#do_action('drop')
endfunction
" AIRLINE
let g:airline_theme='bubblegum'
let g:airline_powerline_fonts=0
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
" HASHIVIM
let g:terraform_align = 1
let g:terraform_fmt_on_save = 1
" INDENTLINE
let g:indentLine_enabled = 1
let g:indentLine_char = ''
" DELIMITMATE
let g:delimitMate_expand_cr = 2
" FZF
command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, {'options': ['--no-preview']}, <bang>0)
command! -bang -nargs=? -complete=dir Tags call fzf#vim#tags(<q-args>, {'options': ['--no-preview']}, <bang>0)
"" Open fuzzy tag finder
nnoremap <silent> <C-t> :Tags<CR>
"" Open fuzzy file searching similar to vscode
nnoremap <silent> <C-p> :Files<CR>
"" Floating window
let $FZF_DEFAULT_OPTS='--layout=reverse'
let $FZF_DEFAULT_COMMAND='rg --files --follow --hidden -g "!{node_modules/*,.git/*}"'
let g:fzf_layout = { 'window': 'call FloatingFZF()' }
function! FloatingFZF()
let buf = nvim_create_buf(v:false, v:true)
call setbufvar(buf, '&signcolumn', 'no')
let height = &lines - 45
let width = float2nr(&columns - (&columns * 2 / 4))
let col = float2nr((&columns - width) / 2)
let opts = {
\ 'relative': 'editor',
\ 'row': 1,
\ 'col': col,
\ 'width': width,
\ 'height': height,
\ 'style': 'minimal'
\ }
call nvim_open_win(buf, v:true, opts)
endfunction
" SNIPPETS
let g:UltiSnipsExpandTrigger = "<C-t>"
let g:UltiSnipsJumpForwardTrigger = "<C-d>"
let g:UltiSnipsJumpBackwardTrigger = "<C-u>"
" GRAPHVIZ
nnoremap <silent> <localleader><localleader> :silent Graphviz! png<CR> <BAR> :silent !rm %:r.png<CR>
" COC
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
"" rebinding to regular CR at the end breaks delimitmate functionality
"" it's not pretty, but it works
imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<Plug>delimitMateCR"
"" GoTo code navigation.
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)
"" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
"" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
"" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
"" Detect django projects
autocmd FileType python let b:coc_root_patterns = ["manage.py"]
" GUTENTAGS
"" only list git-tracked files
let g:gutentags_file_list_command = "rg --files"
" RUST
let g:rustfmt_autosave = 1
" TEST
let g:test#preserve_screen = 1
let g:test#echo_command = 0
let test#neovim#term_position = "vert botright"
let test#strategy = "neovim"
let test#python#runner = 'pytest'
"" Bind C-o to escape to normal mode
if has('nvim')
tmap <C-o> <C-\><C-n>
endif
nmap <silent> <Leader>tf :TestFile<CR>
nmap <silent> <Leader>tt :TestSuite<CR>
nmap <silent> <Leader>tv :TestVisit<CR>
nmap <silent> <Leader>tl :TestLast<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment