Skip to content

Instantly share code, notes, and snippets.

@aehernandez
Last active June 26, 2019 19:22
Show Gist options
  • Save aehernandez/2980246e2ecf78de87e6d05ccd1ad396 to your computer and use it in GitHub Desktop.
Save aehernandez/2980246e2ecf78de87e6d05ccd1ad396 to your computer and use it in GitHub Desktop.
.vimrc
" Usage
" curl https://gist.githubusercontent.com/aehernandez/2980246e2ecf78de87e6d05ccd1ad396/raw/3e0d1d7ccd08cc68d225fb6e0c6d97ff42c154f8/.vimrc > ~/.vimrc && vim
set t_Co=256
syntax on
" colorscheme molokai
set textwidth=120 " break lines when line length increases
set expandtab " enter spaces when tab is pressed
set tabstop=4 " use 4 spaces to represent tab
set softtabstop=4
set shiftwidth=4 " number of spaces to use for auto indent
set autoindent " copy indent from current line when starting a new line
set backspace=2 "Allows you to delete old text/new lines
set nocompatible
set number
set autowrite
set mouse=a " Allows you to click to change line position
set cc=90
au BufRead,BufNewFile *.pde set filetype=arduino
au BufRead,BufNewFile *.ino set filetype=arduino
au BufRead,BufNewFile SConstruct set filetype=python
au BufRead,BufNewFile ZIP_BUILD set filetype=python
" autocmd BufRead,BufNewFile *.ts set filetype=javascript
" Split Bindings
" Use arrow keys to split
" Use hjkl movement keys to move
nnoremap <C-Right> :vsp<CR>
nnoremap <C-Left> :vsp<CR>
nnoremap <C-Up> :sp<CR>
nnoremap <C-Down> :sp<CR>
set splitbelow
set splitright
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
"*************************
set incsearch hlsearch showmatch "Search options
set ignorecase smartcase
nnoremap <CR> :noh<CR><CR>:<backspace>
" ctags
" ctags -R --fields=+l --languages=python --python-kinds=-iv -f ./tags $(python -c "import os, sys; print(' '.join('{}'.format(d) for d in sys.path if os.path.isdir(d)))")
" https://www.fusionbox.com/blog/detail/navigating-your-django-project-with-vim-and-ctags/590/
set tags=~/.tags
" Open declaration of symbol in a new tab
nnoremap g] <C-w><C-]><C-w>T
" Open declaration of symbol in a preview window
nnoremap g} <C-w><C-}>
filetype off
" Load vim-plug
if empty(glob("~/.vim/autoload/plug.vim"))
execute '!mkdir -p ~/.vim/autoload/'
execute '!curl -fLo ~/.vim/autoload/plug.vim https://raw.github.com/junegunn/vim-plug/master/plug.vim'
endif
call plug#begin('~/.vim/plugged')
"Browse Files/Directories
Plug 'https://github.com/scrooloose/nerdtree'
" Move around vim words faster
Plug 'easymotion/vim-easymotion'
" Fuzzy Search
Plug 'https://github.com/ctrlpvim/ctrlp.vim.git'
" Faster Ctrl-P
Plug 'FelikZ/ctrlp-py-matcher'
" QuickFix (buffer window) options
Plug 'yssl/QFEnter'
" Linters and syntax checkers
Plug 'w0rp/ale'
" Add a vertical line for indentation levels
Plug 'Yggdroot/indentLine'
call plug#end()
" Required by vundle
filetype plugin indent on
" *** Ctrl-P Configurations ***
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
let g:ctrlp_working_path_mode = 0 " don't change working directory
" Remap quickfix window to mimic Ctrl-P bindings
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>']
set laststatus=2
" *** Configuration for EasyMotion ***
map <Leader> <Plug>(easymotion-prefix)
"let g:EasyMotion_do_mapping = 1 " Disable default mappings
" `s{char}{char}{label}`
" Need one more keystroke, but on average, it may be more comfortable.
nmap s <Plug>(easymotion-overwin-f1)
" Turn on case insensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
" *** Use Ag as default grep if available ***
if executable('ag')
" set grepprg=ag\ --nogroup\ --nocolor\ --column
set grepprg=ag\ --vimgrep
" set grepformat=%f:%l:%c:%m
" command! -nargs=+ -bang Ag silent! grep <args> | redraw! | botright copen
command -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s --path-to-ignore=~/.agignore --vimgrep -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
" *** Custom Commands ***
"
" Automatically selected headers alphabetically
" `i` ignores case and `u` removes duplicate lines
vnoremap <F5> :sort ui<CR>
" Convert snake_case to camelCase
vnoremap <tab>c :s#_\(\l\)#\u\1#g<CR>
" Convert camelCase to snake_case
vnoremap <tab>s :s#\C\(\<\u[a-z0-9]\+\|[a-z0-9]\+\)\(\u\)#\l\1_\l\2#g<CR>
" Quickly search the token under the cursor using Ag
nnoremap Q :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
" Find and replace all
nnoremap <tab>r :%s/\<<C-r><C-w>\>//g<Left><Left>
" Enable escape behavior even when in :term
" https://github.com/vim/vim/issues/2716
tnoremap <Esc> <C-W>N
tnoremap <Esc><Esc> <C-W>N
set timeout timeoutlen=1000 " Default
set ttimeout ttimeoutlen=100 " Set by defaults.vim
" Toggle paste mode (auto-indent)
set pastetoggle=<F4>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment