Created
September 23, 2019 16:25
-
-
Save nilbus/cf6b39c518869fe79807439225355d57 to your computer and use it in GitHub Desktop.
vim config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Reset autocommands from previous load | |
au! | |
" Load pathogen plugins and reload their help files | |
call pathogen#infect() | |
call pathogen#helptags() | |
" Set leader key to space | |
nmap <Space> <NOP> | |
let mapleader = "\<Space>"" | |
" Don't create swapfiles; I have never used them. | |
set noswapfile | |
" Indent with 2 spaces | |
set shiftwidth=2 | |
set softtabstop=2 | |
set tabstop=2 | |
set expandtab | |
" When wrapping, wrap at 80 characters, except in git commit messages and PR descriptions | |
set textwidth=80 | |
au FileType gitcommit setlocal textwidth=72 | |
au BufWinEnter PULLREQ_EDITMSG setlocal textwidth=0 | |
" Highlight things you've searched for, and press enter or - to un-highlight | |
nnoremap <silent> <cr> <cr>:nohlsearch<cr> | |
" vim-sensible maps ^L to :nohlsearch | |
set hlsearch | |
" Highlight matching braces/parenthesis | |
set showmatch | |
set matchtime=1 | |
" Jump to last position when reopening a file | |
autocmd BufReadPost * | |
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' | |
\ | exe "normal! g`\"" | |
\ | endif | |
" Syntax highlighting | |
syntax on | |
au BufNewFile,BufRead *.tmpl set filetype=html | |
au BufNewFile,BufRead *.avsc set filetype=json | |
" Wait for .5 sec before deciding you weren't trying a key sequence | |
set timeoutlen=500 | |
" Improved tab completion when using :e to open a file, etc. | |
set wildmode=list:longest | |
set wildignore+=*.class | |
" (optional) Keep buffers open in memory (preserve undo history, etc) and just hide them when you close them (but not fugitive buffers) | |
set hidden | |
autocmd BufReadPost fugitive://* set bufhidden=delete | |
" Ignore case when searching unless your search contains uppercase | |
set ignorecase | |
set smartcase | |
" Set the terminal title to the active buffer's filename | |
set title | |
" Prefix each line with the relative number of lines above or below the current line, for quick navigation (eg. 10j) | |
set relativenumber | |
set number | |
" Download Tomorrow-Night.vim into .vim/colors to use this | |
" https://github.com/chriskempson/tomorrow-theme/tree/master/vim/colors | |
colorscheme Tomorrow-Night | |
" Auto-reload .vimrc | |
augroup myvimrc | |
au! | |
au BufWritePost .vimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif | |
augroup END | |
" Remap # to search forward for the word under the cursor (like *) but don't move the cursor, instead of finding the previous match | |
nmap # mp"pyiwb/\<<c-r>p\><cr>`p | |
nmap g# mp"pyiwb/<c-r>p<cr>`p | |
" Map # to search for the contents of the visual selection | |
vnoremap <silent>* <ESC>:call VisualSearch('/')<CR>/<CR> | |
vnoremap <silent># <ESC>:call VisualSearch('?')<CR>?<CR> | |
function! VisualSearch(dirrection) | |
let l:register=@@ | |
normal! gvy | |
let l:search=escape(@@, '$.*/\[]') | |
if a:dirrection=='/' | |
execute 'normal! /'.l:search | |
else | |
execute 'normal! ?'.l:search | |
endif | |
let @/=l:search | |
normal! gV | |
let @@=l:register | |
endfunction | |
" K was never good to me (load the man page for the word under the cursor). Unmap it. | |
noremap K <NOP> | |
" Maximize the current window split with :Max or Ctrl+W Ctrl+M | |
command! Max vert res 999|res 99 | |
nmap <c-w><c-m> :Max<cr> | |
" Map :w!! to save with sudo | |
cmap w!! %!sudo tee > /dev/null % | |
" Map U to open GUndo | |
nmap U :GundoToggle<cr> | |
" Map \d to :Linediff | |
vmap <leader>d :Linediff<cr> | |
" Configure vim GPG plugin to prefer saving in ascii format | |
let g:GPGPreferArmor=1 | |
" Map Ctrl+P for CommandT, and configure | |
nmap <c-p> :CommandT<CR> | |
let g:CommandTMaxFiles=100000 | |
let g:CommandTMatchWindowReverse=1 | |
let g:CommandTHighlightColor='Pmenu' | |
let g:CommandTWildIgnore=&wildignore . ",vendor/bundle,tmp,node_modules" | |
" Replace :grep with Ag, The Silver Searcher | |
if executable('ag') | |
set grepprg=ag\ --nogroup\ --nocolor | |
endif | |
" <leader>g : git grep for word under cursor | |
nnoremap <leader>g :exe ':silent Ggrep' expand('<cword>') '-- app lib'<cr><c-l> | |
nnoremap <leader>G :exe ':silent Ggrep' expand('<cword>') <cr><c-l> | |
" Open cwindow after :Ggrep | |
autocmd QuickFixCmdPost *grep* cwindow | |
" Sometimes switching keybaords causes me to hit ` instead of =... silly Kinesis | |
nmap <c-w>` <c-w>= | |
" Highlight the current line | |
set cursorline | |
" Minimize lag in ruby files | |
set lazyredraw | |
" Fix crontab -e | |
au BufEnter /private/tmp/crontab.* setl backupcopy=yes | |
" Fix vue syntax highlighting (https://github.com/posva/vim-vue#my-syntax-highlighting-stops-working-randomly) | |
autocmd FileType vue syntax sync fromstart | |
" Hide swap files from directory nav | |
let g:netrw_list_hide= '.*\.swp$,\~$,\.orig$' | |
" Do not reuse buffers when navigataing between quickfix lists or CommandT buffers | |
set switchbuf= | |
let g:CommandTAcceptSelectionCommand='e' | |
let g:CommandTAcceptSelectionVSplitCommand='vs' | |
let g:CommandTAcceptSelectionTabCommand='tabe' | |
" Prefix test runner commands with dox-do for doximity projects | |
" au BufReadPost */work/* let g:vroom_command_prefix='~/bin/dox-do.sh' | |
au BufReadPost */work/* let g:vroom_command_prefix='docker-compose -f "/Users/nilbus/work/dox-compose/docker-compose.yml" -f "/Users/nilbus/work/dox-compose/docker-compose.mac.yml" exec activities' | |
" Make ruby syntax highlighting fast again! | |
set regexpengine=1 | |
" Ctags file location | |
set tags=.git/ctags | |
" vim-tmux-navigator mappings | |
let g:tmux_navigator_no_mappings = 1 | |
nnoremap <silent> <esc>h :TmuxNavigateLeft<cr> | |
nnoremap <silent> <esc>j :TmuxNavigateDown<cr> | |
nnoremap <silent> <esc>k :TmuxNavigateUp<cr> | |
nnoremap <silent> <esc>l :TmuxNavigateRight<cr> | |
nnoremap <silent> <esc>\ :TmuxNavigatePrevious<cr> | |
" Custom maps | |
nnoremap <leader>t :tabnew<cr> | |
nnoremap <leader>T :!ctags --languages='-JavaScript'<cr><cr> | |
nnoremap <leader>c :tabc<cr> | |
nnoremap <leader>C :tabo<cr><c-w>o | |
nnoremap <leader>w :w<cr> | |
nnoremap <leader>W :wa<cr> | |
nnoremap <leader>e :e<cr> | |
nnoremap <leader>E :tabdo windo e<cr> | |
nnoremap <leader>q :q<cr> | |
nnoremap <leader>z :wq<cr> | |
nnoremap <leader>a :!git add %<cr><cr> | |
nnoremap <leader>o <c-w>o:tabo<cr> | |
nnoremap <Leader>p "0p | |
nnoremap <Leader>P "0P | |
vnoremap <Leader>p "0p | |
vnoremap <Leader>P "0P | |
nmap <leader>F ggyI# frozen_string_literal: true<cr><cr><esc> | |
nmap <silent> <Leader>R :w<cr>:!rubocop -a % &> /dev/null<cr>L | |
nmap <silent> <leader>A :ALEToggle<cr> | |
nmap <silent> ]r :ALENext<cr> | |
nmap <silent> [r :ALEPrevious<cr> | |
" Use left and right arrow keys to switch between tabs | |
nmap <left> :tabprev<cr> | |
nmap <right> :tabnext<cr> | |
cmap VR VtrSendCommandToRunner! | |
" ale | |
highlight ALEWarning ctermbg=White | |
" Replaced by ale | |
" autocmd BufWritePost *.rb :silent! exec ':!docker-compose -f ~/work/dox-compose/docker-compose.yml exec `basename "$PWD"` rubocop -a % &> /dev/null' | edit | redraw! | |
" autocmd BufWritePost *.rb,*.rake,*.jbuilder :silent! exec ':!rubocop -a % &> /dev/null' | setlocal regexpengine=1 | edit | redraw! | |
" Map Ctrl+D to Delete and Shift+Tab to unindent | |
inoremap <s-tab> <c-d> | |
inoremap <c-d> <del> | |
" easymotion bindings | |
nmap <Leader><Leader>l <Plug>(easymotion-overwin-line) | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" PROMOTE VARIABLE TO RSPEC LET | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
function! PromoteToLet() | |
:normal! dd | |
" :exec '?^\s*it\>' | |
:normal! P | |
:.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/ | |
:normal == | |
endfunction | |
:command! PromoteToLet :call PromoteToLet() | |
:map <leader>l :PromoteToLet<cr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YouCompleteMe | |
ack.vim | |
ag | |
ale | |
command-t | |
delimitMate | |
gundo | |
linediff.vim | |
splitjoin.vim | |
trailertrash.vim | |
vim-abolish | |
vim-align | |
vim-commentary | |
vim-ctrlspace | |
vim-dispatch | |
vim-easymotion | |
vim-eco | |
vim-endwise | |
vim-fugitive | |
vim-gnupg | |
vim-markdown | |
vim-obsession | |
vim-plist | |
vim-polyglot | |
vim-rails | |
vim-repeat | |
vim-ruby | |
vim-sensible | |
vim-surround | |
vim-textobj-ruby | |
vim-textobj-user | |
vim-tmux-navigator | |
vim-tmux-runner | |
vim-unimpaired | |
vim-vroom | |
zencoding-vim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment