Skip to content

Instantly share code, notes, and snippets.

@joseph-ravenwolfe
Last active August 29, 2015 13:56
Show Gist options
  • Save joseph-ravenwolfe/8813762 to your computer and use it in GitHub Desktop.
Save joseph-ravenwolfe/8813762 to your computer and use it in GitHub Desktop.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""" SYSTEM """"""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible " DO NOT USE VI
set rtp+=~/.vim/bundle/vundle/ " SET VUNDLER PATH
call vundle#rc() " USE VUNDLER
set shell=/bin/bash " FIX RVM
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""" GITHUB BUNDLES """"""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Bundle 'gmarik/vundle'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'tpope/vim-rails.git'
Bundle 'tpope/vim-commentary.git'
Bundle 'kien/ctrlp.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'kchmck/vim-coffee-script'
Bundle 'othree/html5.vim'
Bundle 'mattn/emmet-vim'
Bundle 'rking/ag.vim'
Bundle 'vim-scripts/buftabs'
Bundle 'tpope/vim-surround'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""" SYNTAX HIGHLIGHTING """"""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""" FILE TYPE DETECTION """""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
filetype plugin indent on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""" COLOR SCHEME """""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
colorscheme Tomorrow-Night-Eighties
set guifont=Monaco:h17
set t_Co=256 " 256 colors
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""" SPACING AND WRAPPING """""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab " USE SOFT TABS
set softtabstop=2 " USE TWO SPACES FOR SOFT TABS
set shiftwidth=2 " SET << >> INDENTATION TO TWO SPACES
set tabstop=2 " USE TWO SPACES FOR HARD TABS (DISPLAY)
set nowrap " DISABLE SOFT WRAPPING
set textwidth=80 " SET SOFT WRAP TO 80 CHARACTERS
set clipboard=unnamed " YANK TO SYSTEM CLIPBOARD
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""" INTERFACE """""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set rnu " DISPLAY LINE NUMBER
set showcmd " DISPLAY THE CURRENT COMMAND
set vb " ENABLE VISUAL BELL
set ruler " DISPLAY LINE AND COLUMN NUMBER
set wildmode=longest,list,full " ADD A MENU BAR
set wildmenu " ENABLE MENU LISTING SUPPORT
set splitright " SPLIT TO THE RIGHT INSTEAD OF LEFT
set splitbelow " SPLIT TO THE BOTTOM INSTEAD OF TOP
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""" EDITING """"""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set smartindent " INDENT INWARDS IN BLOCKS/FUNCTIONS
set showmode " DISPLAY THE EDITING MODE
set showmatch " HIGHLIGHT CORRESPONDING BRACKETS,
" COMMAS, PARENS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""" MAPPINGS """"""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader = ',' " USE COMMA AS LEADER
noremap <cr> :nohl<cr><cr> " TURN OFF HIGHLIGHT ON ENTER
map <Left> :bp<CR> " NAVIGATE BUFFERS
map <Right> :bn<CR> " NAVIGATE BUFFERS
map <Up> <Nop> " DISABLE, 'K' IS PREFERRED
map <Down> <Nop> " DISABLE, 'J' IS PREFERRED
nmap <leader>t :w\|:!rspec spec; rubocop<cr> " RUN TESTS AND STYLE CHECK
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""" SEARCHING """""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set incsearch " ENABLE SEARCH AS YOU TYPE
set hlsearch " HIGHLIGHT SEARCHES
set ignorecase smartcase " CASE INSENSITIVE REGULAR EXPRESSIONS,
" UNLESS MIXED CASE IN USE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""" FILE STORAGE """""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set autoread " AUTOMATICALLY RELOAD FILE IF CHANGED
set noswapfile " DO NOT USE A SWAP FILE
set nobackup " DO NOT CREATE A SWAP FILE
set nowritebackup " DO NOT SAVE TO A SWAP FILE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""" AUTO RELOAD VIMRC """"""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup myvimrc
au!
au BufWritePost .vimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""" CUSTOM AUTOCOMMANDS """"""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup vimrcEx
" CLEAR ALL AUTOCMDS IN THE GROUP
autocmd!
" FILE TYPES
autocmd BufRead *.sql set filetype=mysql
autocmd BufRead *.thor set filetype=ruby
" JUMP TO LAST CURSOR POSITION UNLESS IT'S INVALID OR IN AN EVENT HANDLER
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" LEAVE THE RETURN KEY ALONE WHEN IN COMMAND LINE WINDOWS, SINCE IT'S USED
" TO RUN COMMANDS THERE.
autocmd! CmdwinEnter * :unmap <cr>
autocmd! CmdwinLeave * :call MapCR()
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""" STRIP WHITESPACE ON SAVE """"""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd BufWritePre * :%s/\s\+$//e
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""" INDENT OR AUTOCOMPLETE WITH TAB KEY """""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
nnoremap <leader><leader> <c-^>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""" NERDTREE CONFIGS BELOW """""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""" OPEN NERDTREE ON BOOT """"""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd vimenter * NERDTree
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""" SHOW CURRENT FILE IN NERDTREE """"""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RETURNS TRUE IF IS NERDTREE OPEN/ACTIVE
"
function! rc:isNTOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" RETURNS TRUE IFF FOCUSED WINDOW IS NERDTREE WINDOW
"
function! rc:isNTFocused()
return -1 != match(expand('%'), 'NERD_Tree')
endfunction
" CALLS NERDTREEFIND IFF NERDTREE IS ACTIVE, CURRENT WINDOW CONTAINS A
" MODIFIABLE FILE, AND WE'RE NOT IN VIMDIFF
"
function! rc:syncTree()
if &modifiable && rc:isNTOpen() && !rc:isNTFocused() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
autocmd BufEnter * call rc:syncTree()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""" CLOSE VIM IF NERDTREE IS THE ONLY OPEN BUFFER """""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment