Skip to content

Instantly share code, notes, and snippets.

@vdinovi
Created January 29, 2021 17:49
Show Gist options
  • Select an option

  • Save vdinovi/936c1cd841d41d432f382612174efad3 to your computer and use it in GitHub Desktop.

Select an option

Save vdinovi/936c1cd841d41d432f382612174efad3 to your computer and use it in GitHub Desktop.
""""""""""""""""""""""""
" Plugins "
""""""""""""""""""""""""
" Plugs
set nocompatible "not vi compatible
call plug#begin('~/.local/share/nvim/plugged')
" Visual
Plug 'junegunn/seoul256.vim' " Color Schema
Plug 'itchyny/lightline.vim' " Status line (alternate to powerline). Requires: laststatus=2
" Actions
Plug 'preservim/nerdcommenter'
" Search / Navigation
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " fuzzy search
Plug 'junegunn/fzf.vim' " fuzzy search vim integration
Plug 'scrooloose/nerdtree' " file tree
Plug 'airblade/vim-rooter' " change pwd to root of nearest git repo on file open
Plug 'majutsushi/tagbar' " visualize tags
" Semantics
Plug 'w0rp/ale' " async linting
" Git
Plug 'tpope/vim-fugitive' " Git integration
" Ruby
Plug 'vim-ruby/vim-ruby'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-rbenv'
Plug 'tpope/vim-bundler'
" Rust
Plug 'rust-lang/rust.vim'
" JS
Plug 'maxmellon/vim-jsx-pretty'
" Web
Plug 'digitaltoad/vim-pug'
" Autocomplete
" apparently requires neovim be installed through pip3, but that didn't even fix it. Too brittle
"Plug 'ncm2/ncm2'
"Plug 'roxma/nvim-yarp'
"Plug 'ncm2/ncm2-bufword'
"Plug 'ncm2/ncm2-path'
" Graveyard
"Plug 'tpope/vim-endwise.git'
"Plug 'vim-airline/vim-airline'
"Plug 'vim-airline/vim-airline-themes'
"Plug 'rking/ag.vim'
"Plug 'ervandew/supertab'
call plug#end()
""""""""""""""""""""""""
" Core "
""""""""""""""""""""""""
syntax on
set encoding=utf-8 " UTF8 bro
set wildmenu " autocomplete menu
set showcmd " show command typing
set hlsearch " highligh searches
set ignorecase " smart search
set smartcase " smarter case for greps
set backspace=indent,eol,start " del these as 1
set autoindent " smart indent
set ruler " show position in file
set confirm " adds y/n/c for confirmations
set visualbell " alternative to beep
set mouse=a " enable mouse
set laststatus=2 " just enough for command buffer
set cmdheight=2 " vert-offset for command buffer
set number " disp line #
set relativenumber
set clipboard=unnamed " allow copy/paste to clipboard
set splitright " new buffer on right
set splitbelow " new buffer below
set softtabstop=4 " make tabs feel like spaces
set shiftwidth=4 " indentation
set expandtab " tabs -> spaces
set textwidth=120 " column width
set tags+=tags;$HOME " keep looking up until home for tags file
set foldmethod=indent
set foldnestmax=10
set nofoldenable
set foldlevel=2
command! Src source ~/.vimrc
" -------------------------------------
" Interface -
" -------------------------------------
let g:seoul256_background=235
color seoul256
highlight LineNr ctermfg=DarkGrey
" Extra Whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\\t/
""""""""""""""""""""""""
" Other "
""""""""""""""""""""""""
let NERDTreeIgnore = ['\.pyc$', '\.swp$']
""""""""""""""""""""""""
" Key Mappings "
""""""""""""""""""""""""
" Leader
let mapleader = ' '
let maplocalleader = ' '
" source vimrc
nnoremap <leader>,e :tabe ~/.vimrc<cr>
nnoremap <leader>,r :Src<cr>
" tab
" jk escape
"inoremap jk <Esc>
"xnoremap jk <Esc>
"cnoremap jk <C-c>
noremap <C-w>v :vnew
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
nnoremap <silent> <C-L> :nohl<CR><C-L>
vmap <C-c> "*y
nmap <C-c> "*Y
nmap <C-v> "*p
nnoremap Y y$
inoremap jk <Esc>
nnoremap <leader>a :Ag
noremap ,. :tabn<cr>
noremap ,, :tabp<cr>
map <Esc><Esc> :w<CR>
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
" fzf
nnoremap <leader><leader> :Files<cr>
"nnoremap <silent> <expr> <Leader><Leader> (expand('%') =~ 'NERD_tree' ? "\<c-w>\<c-w>" : '').":Files\<cr>"
"nnoremap <silent> <leader>C :Colors<cr>
nnoremap <silent> <leader>fb :Buffers<cr>
nnoremap <silent> <leader>fl :Lines<cr>
nnoremap <silent> <leader>fm :Marks<cr>
nnoremap <leader>ft :Tags<cr>
" tags
nnoremap <C-]> g<C-]>
nnoremap g[ :pop<CR>
nnoremap <silent> <leader>tb :TagbarToggle<CR>
nnoremap <silent> <leader>ts :ts<CR>
" nerdtree
nnoremap <leader>n :NERDTreeToggle<cr>
nnoremap <leader>nr :NERDTreeFocus<cr>R<c-w><c-p>
" fugitive
nnoremap <leader>g :Git<cr>
nnoremap <leader>gc :Git commit<cr>
nnoremap <leader>gl :Git log<cr>
nnoremap <leader>gb :Git blame<cr>
nnoremap <leader>gd :Git diff<cr>
nnoremap <leader>gs :Git status<cr>
" copy file path into system clipboard
if has("mac") || has("gui_macvim") || has("gui_mac")
" relative path (src/foo.txt)
nnoremap <leader>cf :let @*=expand("%")<CR>
" absolute path (/something/src/foo.txt)
nnoremap <leader>cF :let @*=expand("%:p")<CR>
" filename (foo.txt)
nnoremap <leader>ct :let @*=expand("%:t")<CR>
" directory name (/something/src)
nnoremap <leader>ch :let @*=expand("%:p:h")<CR>
endif
" -----------------------------------------
" <Leader>?/! | Google it / Feeling lucky -
" -----------------------------------------
function! s:goog(pat, lucky)
let q = '"'.substitute(a:pat, '["\n]', ' ', 'g').'"'
let q = substitute(q, '[[:punct:] ]',
\ '\=printf("%%%02X", char2nr(submatch(0)))', 'g')
call system(printf('open "https://www.google.com/search?%sq=%s"',
\ a:lucky ? 'btnI&' : '', q))
endfunction
nnoremap <leader>? :call <SID>goog(expand("<cWORD>"), 0)<cr>
nnoremap <leader>! :call <SID>goog(expand("<cWORD>"), 1)<cr>
xnoremap <leader>? "gy:call <SID>goog(@g, 0)<cr>gv
xnoremap <leader>! "gy:call <SID>goog(@g, 1)<cr>gv
" -----------------------------------------
" Ale Linter -
" -----------------------------------------
let g:ale_cache_executable_check_failures = 1 " cache Ale check failures
nmap <silent> <leader>aj :ALENext<cr>
nmap <silent> <leader>ak :ALEPrevious<cr>
" -----------------------------------------
" Fzf -
" -----------------------------------------
set rtp+=/usr/local/opt/fzf
set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case " use ripgrep for grep
" FZF act like ctrl-p
nnoremap <C-p> :Files<Cr>
" -----------------------------------------
" Languages -
" -----------------------------------------
" --- Ruby ---
function! Bxr()
silent !clear
execute "!" . "bundle exec ruby" . " " . expand("%:p")
endfunction
nnoremap <leader>rt :call Bxr()
autocmd Filetype ruby setlocal shiftwidth=2 tabstop=2 shiftwidth=2 expandtab textwidth=150
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
" --- C/C++ ---
autocmd Filetype c setlocal tabstop=4 shiftwidth=4 expandtab textwidth=120 cino=:0
autocmd Filetype h setlocal tabstop=4 shiftwidth=4 expandtab textwidth=120 cino=:0
autocmd Filetype cpp setlocal tabstop=4 shiftwidth=4 expandtab textwidth=120 cino=:0
autocmd Filetype cxx setlocal tabstop=4 shiftwidth=4 expandtab textwidth=120 cino=:0
autocmd Filetype hpp setlocal tabstop=4 shiftwidth=4 expandtab textwidth=120 cino=:0
" --- Web ---
autocmd Filetype html setlocal tabstop=2 shiftwidth=2 expandtab
autocmd Filetype javascript setlocal shiftwidth=4 tabstop=4 noexpandtab
autocmd Filetype pug setlocal tabstop=4 shiftwidth=4 noexpandtab
autocmd Filetype css setlocal tabstop=4 shiftwidth=4 expandtab
" --- Python ---
autocmd Filetype python setlocal tabstop=4 shiftwidth=4 expandtab
" --- SQL ---
autocmd Filetype sql setlocal tabstop=4 shiftwidth=4 expandtab
" --- JSON ---
autocmd Filetype json setlocal tabstop=4 shiftwidth=4 expandtab textwidth=120
" --- YAML ---
autocmd Filetype yml setlocal tabstop=2 shiftwidth=2 expandtab textwidth=80 cino=:0
autocmd Filetype yaml setlocal tabstop=2 shiftwidth=2 expandtab textwidth=80 cino=:0
" --- Terraform ---
autocmd Filetype tf setlocal tabstop=2 shiftwidth=2 expandtab textwidth=120 cino=:0
" TODO better folding
"function! RubyMethodFold(line)
" let line_is_method_or_end = synIDattr(synID(a:line,1,0), 'name') == 'rubyMethodBlock'
" let line_is_def = getline(a:line) =~ '\s*def '
" return line_is_method_or_end || line_is_def
"endfunction
"set foldexpr=RubyMethodFold(v:lnum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment