Skip to content

Instantly share code, notes, and snippets.

@audrow
Last active June 21, 2021 16:18
Show Gist options
  • Save audrow/f3e5ae9f1a4b9d9bd8256824a21f27f9 to your computer and use it in GitHub Desktop.
Save audrow/f3e5ae9f1a4b9d9bd8256824a21f27f9 to your computer and use it in GitHub Desktop.
My vimrc
" vim: foldmethod=marker
" Setup instructions
" ------------------
" 1. Setup Vundle
" ```
" git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
" ```
" 2. Copy the contents of this file into `~/.vimrc`
" 3. Install the plugins with `vim +PluginInstall +qall`
" System {{{1
" Setup {{{2
" allows plugins
set nocompatible
filetype plugin on
syntax on
colorscheme desert
" VUNDLE
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim' "required
Plugin 'vim-scripts/AutoComplPop'
" plugin on GitHub repo
" Plugin 'tpope/vim-fugitive' "git plugin
" Plugin 'davidhalter/jedi-vim' "python autocomplete
" Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/nerdtree' "file viewer
Plugin 'git://git.wincent.com/command-t.git'
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" no backup files
set nobackup
set nowritebackup
set noswapfile
set tags=./tags;/ " searches parent directories until it finds a tag
set hidden " disables error when switch from unsaved file
" close autocompletion window after I leave insert mode
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
set wildmode=longest,list
set clipboard=unnamed
let g:gitgutter_enabled=0
set updatetime=100
" Display {{{2
"colorscheme desert
"syntax on
set foldmethod=syntax
set foldcolumn=3
set nolist
" set linebreak
set number
set ruler
set cursorline
set wrap
set tw=0
set hlsearch
" Control {{{2
set mouse=a
let mapleader = "'"
" normal mode {{{3
set nrformats = " sets <C-{a,x}> to increment in decimal
" insert mode {{{3
set pastetoggle=<F2>
set smartindent
set backspace=indent,eol,start
" search {{{3
set history=200
set incsearch " shows matching search result each char entered
set ignorecase " ignore case by defaul (smartcase didn't work for me)
" Key mappings {{{1
" Normal mode {{{2
" Misc {{{3
" toggle folds with space
nnoremap <Space> za
" add empty line above or below
nnoremap go ok
nnoremap gO Oj
" treat wrapped lines as lines
nnoremap k gk
nnoremap gk k
nnoremap j gj
nnoremap gj j
" common EX commands
nnoremap <leader>s "syiw:%s/\<<C-r>s\>/
nnoremap <leader>a "syiw:argdo %s/\<<C-r>s\>/
" unhighlight search matches
nnoremap <silent> <leader>c :<C-u>nohlsearch<CR><C-l>
" paste to line from system clipboard and keep formatting
nnoremap <leader>p :set paste<CR>"+p:set nopaste<CR>
" GitGutter
nnoremap ]h <Plug>GitGutterNextHunk
nnoremap [h <Plug>GitGutterPrevHunk
" Formatting {{{3
nnoremap <leader>i :set breakindent<CR>
nnoremap <leader>fi :set foldmethod=indent<CR>
nnoremap <leader>fs :set foldmethod=syntax<CR>
nnoremap <leader>fm :set foldmethod=marker<CR>
" GitGutter
nnoremap <leader>g :GitGutterToggle<CR>
nnoremap <leader>gh :GitGutterLineHighlightsToggle<CR>
" File operations {{{3
" read, write, quit
nnoremap <leader>w :wa<CR>
nnoremap <leader>Q :wqa<CR>
nnoremap Q :q<CR>
nnoremap QQ :qa<CR>
" misc
nnoremap <leader>f :NERDTree<CR>
nnoremap <leader>rc :e ~/.vimrc<CR>
nnoremap <leader>rct :tabnew ~/.vimrc<CR>
nnoremap <leader>rcv :vsplit ~/.vimrc<CR>
nnoremap <leader>rch :split ~/.vimrc<CR>
nnoremap <leader>l :ls<CR>:b
" windows and tabs {{{4
" move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" window
nnoremap <leader>h :split<CR>
nnoremap <leader>v :vsplit<CR>
nnoremap <leader>o :only<CR>
" tabs
nnoremap <leader>tn :tabnew<CR>
nnoremap <leader>te :tabedit %<CR>
nnoremap <leader>tc :tabclose<CR>
nnoremap <leader>to :tabonly<CR>
" Navigate lists {{{3
" buffer
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap <silent> [B :bfirst<CR>
nnoremap <silent> ]B :bprevious<CR>
" args list
nnoremap <silent> [a :previous<CR>
nnoremap <silent> ]a :next<CR>
nnoremap <silent> [A :first<CR>
nnoremap <silent> ]A :last<CR>
" quickfix: vim grep
nnoremap <silent> [q :cprev<CR>
nnoremap <silent> ]q :cnext<CR>
nnoremap <silent> [Q :cfirst<CR>
nnoremap <silent> ]Q :clast<CR>
" buffer
nnoremap <silent> [h :GitGutterPrevHunk<CR>
nnoremap <silent> ]h :GitGutterNextHunk<CR>
" Insert mode {{{2
" " Parenthesis {{{3
" inoremap ( ()<c-o>i
" inoremap [ []<c-o>i
" inoremap { {}<c-o>i
" inoremap " ""<c-o>i
" File operations {{{3
inoremap <leader>w <c-o>:wa<CR>
inoremap <leader>Q <c-o>:wqa<CR>
" Misc {{{3
" paste from system clipboard with formatting
inoremap <leader>p <C-o>:set paste<CR><C-o>"+p<C-o>:set nopaste<CR>
" Visual mode {{{2
" Treat wrapped lines like lines
vnoremap k gk
vnoremap gk k
vnoremap j gj
vnoremap gj j
" replace
vnoremap <leader>s "sy:%s/\V<C-r>s/
vnoremap <leader>a "sy:argdo %s/\V<C-r>s/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment