Skip to content

Instantly share code, notes, and snippets.

@btall
Last active May 12, 2020 17:19
Show Gist options
  • Save btall/871b01bdb2422e39540959413224481c to your computer and use it in GitHub Desktop.
Save btall/871b01bdb2422e39540959413224481c to your computer and use it in GitHub Desktop.
if !filereadable($HOME.'/.vim/autoload/plug.vim')
!curl -fLo ~/.vim/autoload/plug.vim --create-dirs 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
source $MYVIMRC
endif
call plug#begin('~/.vim/plugins')
Plug 'airblade/vim-gitgutter'
Plug 'aonemd/kuroi.vim'
Plug 'dense-analysis/ale'
Plug 'jeffkreeftmeijer/vim-numbertoggle'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/goyo.vim'
Plug 'machakann/vim-sandwich'
Plug 'simnalamburt/vim-mundo'
Plug 'terryma/vim-multiple-cursors'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
call plug#end()
set autoindent " always set autoindenting on
set autoread " automatically read changes in the file
set background=dark
set backspace=indent,eol,start " make backspace behave properly in insert mode
set clipboard=unnamedplus " use system clipboard; requires has('unnamedplus') to be 1
set colorcolumn=81 " display text width column
set completeopt=longest,menuone,preview " better insert mode completions
set cursorline " highlight current line
set formatoptions-=cro " disable auto comments on new lines
set hidden " hide buffers instead of closing them even if they contain unwritten changes
set hlsearch " highlight search patterns
set ignorecase " searches are case insensitive...
set incsearch " incremental search highlight
set laststatus=2 " always display the status bar
set lazyredraw " lazily redraw screen while executing macros, and other commands
set mouse= " disable the mouse support
set noswapfile " disable swap files
set nowrap " disable soft wrap for lines
set number " display line numbers
set scrolloff=2 " always show 2 lines above/below the cursor
set showcmd " display incomplete commands
set smartcase " ...unless they contain at least one capital letter
set splitbelow " vertical splits will be at the bottom
set splitright " horizontal splits will be to the right
set statusline=%=%m\ %c\ %P\ %f " status line: modifiedflag, charcount, filepercent, filepath
set tabstop=4 shiftwidth=4 softtabstop=4 expandtab " use two spaces for indentation
set t_Co=256 " enable 256 colors
set ttimeoutlen=50 " ...makes for a faster key response
set ttimeout " time waited for key press(es) to complete...
set ttyfast " more characters will be sent to the screen for redrawing
set wildmenu " better menu with completion in command mode
set wildmode=longest:full,full
colorscheme kuroi
autocmd! FileType c setlocal ts=4 sts=4 sw=4 noexpandtab
autocmd! FileType java setlocal ts=4 sts=4 sw=4 expandtab
autocmd! FileType make setlocal ts=8 sts=8 sw=8 noexpandtab
autocmd! FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
autocmd! FileType vim setlocal ts=2 sts=2 sw=2 expandtab
"remove current line highlight in unfocused window
au VimEnter,WinEnter,BufWinEnter,FocusGained,CmdwinEnter * set cul
au WinLeave,FocusLost,CmdwinLeave * set nocul
"remove trailing whitespace on save
autocmd! BufWritePre * :%s/\s\+$//e
"The Leader
let mapleader=","
nnoremap ! :!
nnoremap <leader>w :w<cr>
"replace the word under cursor
nnoremap <leader>* :%s/\<<c-r><c-w>\>//g<left><left>
"toggle showing hidden characters
nnoremap <silent> <leader>s :set nolist!<cr>
"toggle spell checking
nnoremap <leader>ss :setlocal spell!<cr>
"toggle RTL mode
nnoremap <silent> <leader>l :set rl!<cr>
"override system files by typing :w!!
cnoremap w!! %!sudo tee > /dev/null %
"remove search highlight
nmap <leader>q :nohlsearch<CR>
"jsonify the avro selected_data retrieved from CCC
nnoremap <leader>m :%s/\s{\n\s*"\(int\\|string\\|boolean\)": \(.*\)\n\s*}/ \2/g<cr>
"move lines around
nnoremap <leader>k :m-2<cr>==
nnoremap <leader>j :m+<cr>==
xnoremap <leader>k :m-2<cr>gv=gv
xnoremap <leader>j :m'>+<cr>gv=gv
"keep text selected after indentation
vnoremap < <gv
vnoremap > >gv
"fzf
nnoremap <leader>p :FZF<cr>
nnoremap <leader>o :Lines<cr>
nnoremap <leader>t :Tags<cr>
nnoremap <leader>r :Buffers<cr>
nnoremap \ :Ag<space>
nnoremap \| :Ag <C-R><C-W><cr>:cw<cr>
"Ctags
set tags+=.git/tags
nnoremap <leader>ct :!ctags -Rf .git/tags --tag-relative --extras=+f --exclude=.git,pkg --languages=-sql<cr><cr>
" Mundo
" A git mirror of mundo.vim
let g:mundo_width = 60
let g:mundo_preview_height = 40
let g:mundo_right = 1
set undofile
set undodir=~/.vim/undo
nnoremap <F5> :MundoToggle<CR>
"GitGutter
autocmd BufWritePost * GitGutter
nnoremap <c-N> :GitGutterNextHunk<CR>
nnoremap <c-P> :GitGutterPrevHunk<CR>
nnoremap <c-U> :GitGutterUndoHunk<CR>
nnoremap <leader>B :enew<cr>
nnoremap <Tab> :bnext<cr>
nnoremap <S-Tab> :bprevious<cr>
nnoremap <leader>bq :bp <bar> bd! #<cr>
nnoremap <leader>ba :bufdo bd!<cr>
"cycle between last two open buffers
nnoremap <leader><leader> <c-^>
function! GitStatus()
let [a,m,r] = GitGutterGetHunkSummary()
return printf(' +%d ~%d -%d', a, m, r)
endfunction
set statusline+=%{GitStatus()}
"netrw
let g:netrw_banner=0
let g:netrw_winsize=20
let g:netrw_liststyle=3
let g:netrw_localrmdir='rm -rf'
nnoremap <leader>n :Lexplore<CR>
" Asynchronous Lint Engine
let g:ale_open_list = 1
let g:ale_keep_list_window_open = 1
"move to the split in the direction shown, or create a new split
nnoremap <silent> <C-h> :call WinMove('h')<cr>
nnoremap <silent> <C-j> :call WinMove('j')<cr>
nnoremap <silent> <C-k> :call WinMove('k')<cr>
nnoremap <silent> <C-l> :call WinMove('l')<cr>
function! WinMove(key)
let t:curwin = winnr()
exec "wincmd ".a:key
if (t:curwin == winnr())
if (match(a:key,'[jk]'))
wincmd v
else
wincmd s
endif
exec "wincmd ".a:key
endif
endfunction
"Goyo
nnoremap <leader>g :Goyo<cr>
if !exists('*s:goyo_leave')
function s:goyo_leave()
source $MYVIMRC
endfunction
endif
autocmd! User GoyoLeave nested call <SID>goyo_leave()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment