Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
534 lines (443 sloc) 16.5 KB
" vim-plug package manager configuration
call plug#begin('~/.vim/plugged')
" Download vim-plug if not present
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
" Vimplug
" To delete a plugin :PlugClean
" To navigate files
Plug 'scrooloose/nerdtree'
" To quickly open a file
Plug 'ctrlpvim/ctrlp.vim'
" Use ctrlp to jump between tags
Plug 'ivalkeen/vim-ctrlp-tjump'
" Use ctrlp with Ag to search
Plug 'lokikl/vim-ctrlp-ag'
" Editor theme
Plug 'tomasr/molokai'
" Run tests using hotkeys
Plug 'janko-m/vim-test'
" Better way to open the files from a quickfix window
Plug 'yssl/QFEnter'
" Buffer explorer
Plug 'jlanzarotta/bufexplorer'
" Close buffer without losing the split
Plug 'moll/vim-bbye'
" Surround a piece of text
Plug 'tpope/vim-surround'
" Makes vim-surround commands repeatable with dot
Plug 'tpope/vim-repeat'
" Vim plugin to issue git commands
Plug 'tpope/vim-fugitive'
" Goes with vim fugitive to open commits on github
Plug 'tpope/vim-rhubarb'
" Git plugin to show git changes
Plug 'airblade/vim-gitgutter'
" Save the vim session
Plug 'xolox/vim-misc'
Plug 'xolox/vim-session'
" Ruby specific support plugins
Plug 'vim-ruby/vim-ruby'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-rbenv'
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-dispatch'
" Easily select parts of a line
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-line'
Plug 'nelstrom/vim-textobj-rubyblock'
" Easily create scratch windows
Plug 'mtth/scratch.vim'
" Copy file path
Plug 'mottalrd/copypath.vim'
" Add comments
Plug 'tpope/vim-commentary'
" Close quotes / parenthesis
Plug 'jiangmiao/auto-pairs'
" Visualise undo tree
Plug 'mbbill/undotree'
" Autocomplete
Plug 'ervandew/supertab'
" Highlight text objects when you select them using hotkeys
Plug 'machakann/vim-highlightedyank'
" Indexed search, shows the number of matches
Plug 'henrik/vim-indexed-search'
" Better yank register
Plug 'maxbrunsfeld/vim-yankstack'
" Copy RTF for presentation
" Plug 'zerowidth/vim-copy-as-rtf'
" Didn't work but can use the following
" :TOhtml command and then
" textutil -convert rtf -stdout <html_file> | pbcopy
" Initialize plugin system
call plug#end()
" Call on custom plugin options from an external file
if filereadable(expand("~/.vim/vimrc.functions"))
source ~/.vim/vimrc.functions
" Recognize the type of the file and set the 'filetype' option.
" Can be used to set the syntax highlighting, set options, etc.
filetype plugin indent on
" Disable Vi compatible mode
set nocompatible
" Enable syntaxt detection based on the file type
syntax on
" Line numbers enabled
set number
set termguicolors
colorscheme molokai
" Hightlight line with cursor
set cursorline
hi CursorLine term=bold cterm=bold guibg=#303030
" Tell vim how many columns a tab counts for
set tabstop=2
" Indentation with 2 spaces when using << or >>
set shiftwidth=2
" Sets the number of columns for a TAB
set softtabstop=2
" Expand TABs to spaces
set expandtab
" Enable bottom right numbers
set ruler
" Folds always open by default
" In YAML files I need to set this explicitly
set foldmethod=indent
set foldlevel=20
" Make backspace behave in a sane manner.
set backspace=indent,eol,start
" Enable mouse support
set mouse=a
if !exists("*ReloadVimrc")
function ReloadVimrc()
source ~/.vim/vimrc
command! ReloadVimrc :call ReloadVimrc()
" Standard “free” key where you can place custom mappings under
let mapleader = ","
" Keep backward char search (opposite of ; to repeat last f{char})
noremap ;; ;
noremap ;b ,
" More intuitive movement on softwrap
vmap <C-j> gj
vmap <C-k> gk
nmap <C-j> gj
nmap <C-k> gk
" Autosave on buffer leave
autocmd BufLeave * silent! wall
" Use par for text formatting (use gqip to format your paragraph)
" Format the text you want to higlight with gq
set formatprg=par\ -q
" Language aware completion
set omnifunc=syntaxcomplete#Complete
function EnableWriting()
set textwidth=72 " Default of par
set formatoptions+=t
highlight Normal guifg=#a3a3a3 guibg=Black
set spell spelllang=en_us
set statusline+=%=%{WordCount()}\ words
function DisableWriting() abort
set textwidth=0
set formatoptions=tcqj
set nospell
set statusline&
command! DisableWriting :call DisableWriting()
command! EnableWriting :call EnableWriting()
" Save automatically when text is changed with vim-auto-save
" let g:auto_save = 1
" let g:auto_save_in_insert_mode = 0
" vim-session configuration
let g:session_autosave = 'yes'
let g:session_autoload = 'yes'
let g:session_directory = ".vim-session"
set lazyredraw
" Enable clipboard on macosx
" also see :help clipboard on nvim
if has('unnamedplus')
set clipboard+=unnamed,unnamedplus
" Open new split panes to right and bottom, which feels more natural than Vim’s default:
set splitbelow
set splitright
" Toggle spellchecking
function! ToggleSpellCheck()
set spell!
if &spell
" This is because the highlight setting
" was getting overridden somehow by language settings
syntax off
echo "Spellcheck ON"
syntax on
echo "Spellcheck OFF"
nnoremap <silent> <leader>z :call ToggleSpellCheck()<CR>
" Wordcount without the need of adding a status bar to vim
function! WordCount()
let s:old_status = v:statusmsg
let position = getpos(".")
exe ":silent normal g\<c-g>"
let stat = v:statusmsg
let s:word_count = 0
if stat != '--No lines in buffer--'
if stat =~ "^Selected"
let s:word_count = str2nr(split(v:statusmsg)[5])
let s:word_count = str2nr(split(v:statusmsg)[11])
let v:statusmsg = s:old_status
call setpos('.', position)
return s:word_count
" Copy path to unnamed register
let g:copypath_copy_to_unnamed_register = 1
" Copy to system clipboard
" When mouse enabled (set mouse=a) hold the Alt key while
" highlighting the text
if !has('nvim')
vmap <D-c> "+yi
vmap <D-x> "+c
vmap <D-v> c<ESC>"+p
imap <D-v> <ESC>"+pa
" Reload buffer when changed on disk
if has('nvim')
autocmd BufEnter,FocusGained * checktime
" Easier way to exit terminal mode in nvim
if has('nvim')
tnoremap <Esc> <C-\><C-n>
tnoremap <C-v><Esc> <Esc>
" Copy all file
nnoremap <C-g> <esc>ggVG<CR>
" Close quickfix
nnoremap <leader>qn :ccl<CR>
" Close buffer without losing the split from vim-bbye plugin
nnoremap <leader>qb :Bdelete<CR>
" Go back to terminal with leader space instead of Ctrl-Z
nnoremap <leader><Space> <C-Z>
" Quick save
noremap <Leader>s :update<CR>
" Delete current file
" Go to the previous buffer, then remove it from the disk (# is a
" reference to the buffer we just left), and then from the buffers list
nnoremap <leader>df :bp \| :call delete(expand('#')) \| :bd!#<CR>
" Remove highlight
nnoremap <leader>h :nohl<CR>
" Easier folding
nnoremap <leader>af zM
nnoremap <leader>ad zR
nnoremap <leader>aa za
" For YAML do
" :setlocal foldmethod=indent
" Yank registers
call yankstack#setup()
nmap <leader>v <Plug>yankstack_substitute_older_paste
nmap <leader>c <Plug>yankstack_substitute_newer_paste
let g:yankstack_map_keys = 0
" Quick git commands
nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gb :Gblame<CR>
nnoremap <leader>gd :Gdiff<CR>
nnoremap <leader>gr :GitGutterUndoHunk<CR>
nnoremap <leader>gh :GitGutterPreviewHunk<CR>
let g:fugitive_summary_format = '%cD - %s'
" Add a binding.pry or debugger for JS
autocmd FileType ruby nnoremap <leader>tb <S-O>binding.pry<Esc>
autocmd FileType javascript nnoremap <leader>tb <S-O>debugger<Esc>
" Shifting blocks visually
" In normal mode can't happen because it conflicts with Ctrl-i
" nnoremap <Tab> >>_
" nnoremap <S-Tab> <<_
" inoremap <S-Tab> <C-D>
vnoremap <Tab> >gv
vnoremap <S-Tab> <gv
" Center the screen when jumping back
nnoremap <C-o> <C-o>zz
" Quickly open nerdtree
" Also with ctrlp-nerdtree plugin for search
nnoremap <leader>ne :NERDTree<cr>
nnoremap <leader>nf :CtrlPNerdTree<cr>
" Show hidden files
let NERDTreeShowHidden=1
let g:ctrlp_nerdtree_show_hidden = 1
" bufexplorer plugin <leader>be to choose a buffer to edit
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1
nnoremap <leader>bo :b#<cr>
" Undotree persistent configuration
set undodir=~/.vim/undodir
set undofile
" vim-test mappings
" these "Ctrl mappings" work well when Caps Lock is mapped to Ctrl
nmap <leader>tn :TestNearest<CR>
nmap <leader>tf :TestFile<CR>
nmap <leader>ts :TestSuite<CR>
nmap <leader>tl :TestLast<CR>
nmap <leader>tv :TestVisit<CR>
" With binstubs there is a change that you might endup using Spring.
let test#ruby#use_binstubs = 0
" vim-test uses Vim8 Terminal to run test commands with term_start() in a split window.
if has('nvim')
let test#strategy = "neovim"
let test#strategy = "vimterminal"
" vim-ctrlp-ag configuration already does the following
" Use ag over grep
" set grepprg=ag\ --nogroup\ --nocolor\ --hidden
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
" let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'
nnoremap <c-f> :CtrlPag<cr>
vnoremap <c-f> :CtrlPagVisual<cr>
nnoremap <leader>ca :CtrlPagLocate
nnoremap <leader>cp :CtrlPagPrevious<cr>
let g:ctrlp_ag_ignores = '--ignore .git
\ --ignore "deps/*"
\ --ignore "_build/*"
\ --ignore "node_modules/*"
\ --ignore "tags"'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
" Add custom tags here, jump with :tag <tagname> or :tselect <tagname>
set tags+=my_tags
" bind K to grep word under cursor
nnoremap K :silent! grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
" bind \ (backward slash) to grep shortcut
function! Ag(args) abort
execute "silent! grep!" shellescape(a:args)
command! -nargs=+ -complete=file Ag call Ag(<q-args>)
nnoremap \ :Ag<SPACE>
" Write a log of what I am working on
function! WriteLog()
let titleString = expand('%:t')
if len(titleString) > 0
let &titlestring = expand('%:t')
let cmd = 'silent !personal_log "'.&titlestring.'"'
execute cmd
autocmd BufWritePost,BufEnter * call WriteLog()
" Better % to jump between keywords
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime! macros/matchit.vim
if &synmaxcol == 3000
" Lowering this improves performance in files with long lines.
set synmaxcol=500
" Leave some space when scrolling down
set scrolloff=3
" Spaces also in normal mode
nnoremap <space> i<space><esc>
" Hotkey to reformat code
nnoremap <leader>fa gg=G
" Highlight word when double clicked
" Use :noh to then remove the highlight
nnoremap <silent> <2-LeftMouse> :let @/='\V\<'.escape(expand('<cword>'), '\').'\>'<cr>:set hls<cr>
" QFEnter plugin for better open a quickfix window
" Userful in conjuction with CtrlP such that it behaves in the same way
let g:qfenter_keymap = {}
let g:qfenter_keymap.vopen = ['<C-v>']
let g:qfenter_keymap.hopen = ['<C-CR>', '<C-s>', '<C-x>']
let g:qfenter_keymap.topen = ['<C-t>']
" Store temporary files in a central spot
set backup
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
" Create ctags using Exuberant Ctags
" as an alternative
" ctags -R --languages=ruby --exclude=.git --exclude=log . $(bundle list --paths)<cr>
" Ctags using the ruby-specific
" Local re-index
nnoremap <leader>ctl :Dispatch ripper-tags -R --exclude=.git --exclude=log<cr>
" Global re-index
nnoremap <leader>cta :Dispatch ripper-tags -R --exclude=.git --exclude=log . $(bundle list --paths \| sed 's/$/\/lib/')<cr>
" Shortlist gems
let libs_pipe_separated = join(split($WORK_GEMS, ","), "\\|")
execute "nnoremap <leader>cts :Dispatch ripper-tags -R --exclude=.git --exclude=log . $(bundle list --paths \\| sed 's/$/\\/lib/' \\| grep -E \"(".libs_pipe_separated.")\")<cr>"
" vim-ruby configuration
let ruby_fold = 1
let ruby_foldable_groups = 'def do'
let ruby_spellcheck_strings = 1
" Cool ctags navigation with vim-ctrlp-tjump
nnoremap <c-]> :CtrlPtjump<cr>
vnoremap <c-]> :CtrlPtjumpVisual<cr>
let g:ctrlp_tjump_only_silent = 1
" Set a nicer foldtext function
set foldtext=MyFoldText()
highlight Folded guibg=black guifg=yellow
" Set prettier as a formatter for Javascript
autocmd FileType javascript set formatprg=prettier\ --stdin
" Please, no Spring in Rails.
" Ideally that would be loaded from the bash, but for some reason it does not.
" MAYBE: Automatically generate ctags for rbenv Ruby stdlibs
" MAYBE: Automatic ctags generation on gem install
" MAYBE: Syntaxt checking
" MAYBE: Show indentation levels
" MAYBE: Working with HAML using vim-haml Tim Pope
" MAYBE: Make tables aligned with
" Easily copy and paste text from vim to another terminal
" Snippets solution
" Automatically sets shiftwidth and expandtab
" Automatically run code linters
You can’t perform that action at this time.