Last active
March 3, 2019 20:14
-
-
Save indrayam/8dd9fb228c18bfa791a71e091ed081a1 to your computer and use it in GitHub Desktop.
My .vimrc (as of March 2019)
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
" .vimrc | |
" Maintained by: Anand Sharma | |
" [email protected] | |
" Heavily borrowed from https://github.com/zanshin/dotfiles | |
" Need more studying: https://bitbucket.org/sjl/dotfiles/src/4e6f3d36c2417fd778f30192b90c51795bdcd368/vim/vimrc?at=default | |
" | |
" ------------------------------------------------------------------- | |
" Forget compatibility with vi | |
" ------------------------------------------------------------------- | |
set nocompatible | |
" ------------------------------------------------------------------- | |
" setup Vundle to manage plugins | |
" ------------------------------------------------------------------- | |
" turn filetype on so that we can turn if off without generating an exit code | |
" of 1 when quiting vim. | |
filetype on " best to have it on before turning it off | |
filetype off " needs to be off to setup Vundle | |
set rtp+=~/.vim/bundle/Vundle.vim " add vundle to run time path | |
call vundle#rc() | |
" let Vundle manage Vundle | |
Plugin 'VundleVim/Vundle.vim' | |
" Tim Pope's Plugin for surrounding text | |
Plugin 'tpope/vim-surround' | |
Plugin 'tpope/vim-commentary' | |
" Git related Bundles | |
Plugin 'tpope/vim-fugitive' | |
Plugin 'airblade/vim-gitgutter' | |
" Bundles for Text Search | |
Plugin 'mileszs/ack.vim' | |
" Bundles related to Themes | |
Plugin 'sjl/badwolf.git' | |
" Bundles related to saving sessions | |
Plugin 'tpope/vim-obsession' | |
" Bundle for Fuzzy Search across files | |
Plugin 'kien/ctrlp.vim' | |
" Vim airline (as a replacement for vim-powerline) | |
Plugin 'vim-airline/vim-airline' | |
Plugin 'vim-airline/vim-airline-themes' | |
" Emoji in Vim :-) | |
Plugin 'junegunn/vim-emoji' | |
" Vim Go | |
Plugin 'fatih/vim-go' | |
Plugin 'AndrewRadev/splitjoin.vim' | |
" Visual Code Dark Scheme | |
" Plugin 'tomasiser/vim-code-dark' | |
if has('autocmd') | |
filetype plugin indent on " enable plugins, detection and indenting | |
endif | |
if has('syntax') && !exists('g:syntax_on') | |
syntax on | |
endif | |
" ------------------------------------------------------------------- | |
" change map <leader> from \ to , | |
" ------------------------------------------------------------------ | |
:let mapleader = "," | |
" ------------------------------------------------------------------- | |
" Allow saving of files as sudo when I forgot to start vim using sudo. | |
" ------------------------------------------------------------------- | |
cmap w!! w !sudo tee > /dev/null % | |
" ------------------------------------------------------------------- | |
" time out mappings after 1 second (1000) | |
" and key codes after 1/2 a second (500) | |
" ------------------------------------------------------------------- | |
set timeout timeoutlen=1000 ttimeoutlen=500 | |
" ------------------------------------------------------------------- | |
" Trying to break a very old habit... | |
" ex mode commands made easy | |
" ------------------------------------------------------------------- | |
nnoremap ; : | |
nnoremap Q <nop> | |
" ------------------------------------------------------------------- | |
" basic options | |
" ------------------------------------------------------------------- | |
set laststatus=2 " always show the status line | |
set cmdheight=2 " and use a two-line tall status line | |
set showcmd " show the command | |
set noshowmode " don't show the mode, vim-airline will do that for us | |
set autoindent " turns it on | |
set smartindent " does the right thing (mostly) in programs | |
set linespace=3 " prefer a slight higher line height | |
set linebreak " wrap intelligently, won't insert hard line breaks | |
set wrap " use line wrapping | |
set textwidth=79 " at column 79 | |
set ruler " display current cursor position | |
set list " show invisible characters | |
set listchars=tab:▸\ ,eol:¬,trail:⋅,nbsp:␣,extends:❯,precedes:❮ | |
set showmatch " show matching brackets | |
set relativenumber " use relative line numbers | |
set number " all lines show their relative numbers, except the line you're currently on | |
set backspace=indent,eol,start " make backspace behave in a sane manner | |
set mousehide " hide mouse when typing | |
set foldenable " enable code folding | |
set history=1000 | |
set ffs=unix,mac,dos " default file types | |
set autoread " automatically update file when edited outside of vim | |
" Setup automatic text formatting/wrapping (previously: grn1 ) | |
set formatoptions= | |
set formatoptions-=t " don't autowrap text | |
set formatoptions+=c " do autowrap comments | |
set formatoptions+=r " automatically continue comments | |
set formatoptions+=o " automatically continue comments when hitting 'o' or 'O' | |
set formatoptions+=q " allow formating of comments with 'gq' | |
set formatoptions+=n " recognize numbered lists | |
set formatoptions+=l " don't break long lines that were already there | |
" ------------------------------------------------------------------- | |
" Navigation and movement | |
" ------------------------------------------------------------------- | |
" disable arrow keys | |
map <up> <nop> | |
map <down> <nop> | |
map <left> <nop> | |
map <right> <nop> | |
imap <up> <nop> | |
imap <down> <nop> | |
imap <left> <nop> | |
imap <right> <nop> | |
" use <C>hjkl to switch between splits | |
nnoremap <C-h> <C-w>h | |
nnoremap <C-j> <C-w>j | |
nnoremap <C-k> <C-w>k | |
nnoremap <C-l> <C-w>l | |
" ------------------------------------------------------------------- | |
" Encoding | |
" ------------------------------------------------------------------- | |
set termencoding=utf-8 " we like utf-8 | |
set encoding=utf-8 | |
" ------------------------------------------------------------------- | |
" What to do with files and focus | |
" ------------------------------------------------------------------- | |
set autowrite " write out old file when switching between files | |
set autoread " reload files changed on disk, i.e. via `git checkout` | |
au FocusLost * :wa " save file when Vim loses focus | |
set hidden " switch beteen buffers without saving | |
" ------------------------------------------------------------------- | |
" With Git who needs backup files? | |
" ------------------------------------------------------------------- | |
set nobackup | |
set noswapfile | |
" ------------------------------------------------------------------- | |
" Set tab stuff | |
" ------------------------------------------------------------------- | |
set tabstop=2 " 2 spaces for a tab | |
set shiftwidth=2 " 2 spaces for autoindenting | |
set softtabstop=2 " when <BS>, pretend a tab is removed even if spaces | |
set expandtab " expand tabs to spaces (overloadable by file type) | |
" ------------------------------------------------------------------- | |
" Scrolling | |
" ------------------------------------------------------------------- | |
set scrolloff=5 " show context above/below cursor line | |
set sidescrolloff=10 " number of cols from horizontal edge to start scrolling | |
set sidescroll=1 " number of cols to scroll at a time | |
" ------------------------------------------------------------------- | |
" Miscellaneous | |
" ------------------------------------------------------------------- | |
" toggle listchars on or off | |
noremap <Leader>l :set list!<CR> | |
" toggle relativenumber on or off | |
noremap <Leader>n :set rnu! <bar> :set number!<CR> | |
" Paste mode to prevent autoindentation of pasted lines | |
set pastetoggle=<F2> | |
" Better pasting from clipboard | |
" http://tilvim.com/2014/03/18/a-better-paste.html | |
map <Leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr> | |
set clipboard=unnamed " yank and paste with the system clipboard | |
" show cursorline only in active window | |
if has("autocmd") | |
autocmd WinLeave * set nocursorline | |
autocmd WinEnter * set cursorline | |
endif | |
" Map escape to jj -- much faster to reach and type | |
imap jj <esc> | |
" ------------------------------------------------------------------- | |
" Searching | |
" ------------------------------------------------------------------- | |
set incsearch " use incremental search | |
set hlsearch " highlight search results | |
set ignorecase " ignore case when searching | |
set smartcase " ignore case if search string is all lower case, case-sensitve otherwise | |
" remove search highlighting with <F3> | |
nnoremap <silent> <leader><leader> :nohlsearch<CR> | |
" ------------------------------------------------------------------- | |
" Completion | |
" ------------------------------------------------------------------- | |
set wildmode=list:longest | |
set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches | |
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing | |
set wildignore+=*vim/backups* | |
set wildignore+=*sass-cache* | |
set wildignore+=*DS_Store* | |
set wildignore+=vendor/rails/** | |
set wildignore+=vendor/cache/** | |
set wildignore+=*.gem | |
set wildignore+=log/** | |
set wildignore+=tmp/** | |
set wildignore+=*.png,*.jpg,*.gif | |
" ------------------------------------------------------------------- | |
" Splits | |
" ------------------------------------------------------------------- | |
nnoremap <leader>v <C-w>v<C-w>l " open a vertical split and switch to it (,v) | |
nnoremap <leader>h <C-w>s<C-w>j " open a horizontal split and switch to it (,h) | |
" ------------------------------------------------------------------- | |
" vimrc shortcuts | |
" ------------------------------------------------------------------- | |
" open vimrc in new tab for editing | |
nmap <leader>ev :edit $MYVIMRC<cr> | |
" automatically source .vimrc when it is saved (from vimcasts.org #24) | |
if has("autocmd") | |
autocmd! bufwritepost .vimrc source $MYVIMRC | |
endif | |
" reload .vimrc | |
map <silent> <leader>V :source ~/.vimrc<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR> | |
" ------------------------------------------------------------------- | |
" Stuff for Bundles | |
" ------------------------------------------------------------------- | |
" Settings for 'sjl/badwolf.git' | |
set background=dark | |
silent! colorscheme badwolf | |
let g:badwolf_darkgutter = 1 " Make the gutters darker than the background | |
" vim-airline configurations | |
let g:airline#extensions#tabline#enabled = 1 | |
let g:airline#extensions#tabline#left_sep = ' ' | |
let g:airline#extensions#tabline#left_alt_sep = '|' | |
let g:airline_powerline_fonts = 1 | |
" Settings for vim-go | |
" Enable to copy to clipboard for operations like yank, delete, change and put | |
" http://stackoverflow.com/questions/20186975/vim-mac-how-to-copy-to-clipboard-without-pbcopy | |
if has('unnamedplus') | |
set clipboard^=unnamed | |
set clipboard^=unnamedplus | |
endif | |
let g:go_fmt_command = "goimports" | |
let g:go_autodetect_gopath = 1 | |
let g:go_list_type = "quickfix" | |
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck'] | |
let g:go_metalinter_autosave = 1 | |
let g:go_metalinter_autosave_enabled = ['vet', 'golint'] | |
let g:go_metalinter_deadline = "5s" | |
let g:go_highlight_types = 1 | |
let g:go_highlight_fields = 1 | |
let g:go_highlight_functions = 1 | |
let g:go_highlight_function_calls = 1 | |
let g:go_highlight_extra_types = 1 | |
let g:go_highlight_generate_tags = 1 | |
" Open :GoDeclsDir with ctrl-g | |
nmap <C-g> :GoDeclsDir<cr> | |
imap <C-g> <esc>:<C-u>GoDeclsDir<cr> | |
augroup go | |
autocmd! | |
" Show by default 4 spaces for a tab | |
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4 | |
" :GoBuild and :GoTestCompile | |
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR> | |
" :GoTest | |
autocmd FileType go nmap <leader>t <Plug>(go-test) | |
" :GoRun | |
autocmd FileType go nmap <leader>r <Plug>(go-run) | |
" :GoDoc | |
autocmd FileType go nmap <Leader>d <Plug>(go-doc) | |
" :GoCoverageToggle | |
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle) | |
" :GoInfo | |
autocmd FileType go nmap <Leader>i <Plug>(go-info) | |
" :GoMetaLinter | |
autocmd FileType go nmap <Leader>l <Plug>(go-metalinter) | |
" :GoDef but opens in a vertical split | |
autocmd FileType go nmap <Leader>v <Plug>(go-def-vertical) | |
" :GoDef but opens in a horizontal split | |
autocmd FileType go nmap <Leader>s <Plug>(go-def-split) | |
" :GoAlternate commands :A, :AV, :AS and :AT | |
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit') | |
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit') | |
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split') | |
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe') | |
augroup END | |
" build_go_files is a custom function that builds or compiles the test file. | |
" It calls :GoBuild if its a Go file, or :GoTestCompile if it's a test file | |
function! s:build_go_files() | |
let l:file = expand('%') | |
if l:file =~# '^\f\+_test\.go$' | |
call go#test#Test(0, 1) | |
elseif l:file =~# '^\f\+\.go$' | |
call go#cmd#Build(0) | |
endif | |
endfunction | |
" CtrlP configuration | |
let g:ctrlp_map = '<c-p>' | |
let g:ctrlp_cmd = 'CtrlP' | |
let g:ctrlp_working_path_mode = 'ra' | |
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$' | |
" The Silver Searcher | |
if executable('ag') | |
" Use ag over grep | |
set grepprg=ag\ --nogroup\ --nocolor | |
" bind K to grep word under cursor | |
nnoremap <C-d> :grep! "\b<C-R><C-W>\b"<CR>:cw<CR> | |
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore | |
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""' | |
" ag is fast enough that CtrlP doesn't need to cache | |
let g:ctrlp_use_caching = 0 | |
endif | |
" Dealing with Buffers more efficiently | |
:nnoremap <Tab> :bnext<CR> | |
:nnoremap <S-Tab> :bprevious<CR> | |
:nnoremap <C-X> :bdelete<CR> | |
" Set some defaults | |
:set nolist | |
" Ack.vim configuration | |
let g:ackprg = 'ag --vimgrep --smart-case' | |
cnoreabbrev ag Ack | |
cnoreabbrev aG Ack | |
cnoreabbrev Ag Ack | |
cnoreabbrev AG Ack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment