Skip to content

Instantly share code, notes, and snippets.

@regedarek

regedarek/.vimrc Secret

Created October 28, 2013 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regedarek/4632cbcfc655899c934f to your computer and use it in GitHub Desktop.
Save regedarek/4632cbcfc655899c934f to your computer and use it in GitHub Desktop.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vundle
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible " be iMproved
filetype off " required!
filetype plugin indent on " required!
set rtp+=~/.vim/bundle/vundle/ " Vundle required!
call vundle#rc() " Vundle required!
Bundle 'gmarik/vundle'
Bundle 'mileszs/ack.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'kien/ctrlp.vim'
Bundle 'nathanaelkane/vim-indent-guides'
Bundle 'KurtPreston/vim-autoformat-rails'
Bundle 'SirVer/ultisnips'
Bundle 'ervandew/supertab'
Bundle 'airblade/vim-rooter'
Bundle 'vim-ruby/vim-ruby'
Bundle 'tpope/vim-rails'
Bundle 'tpope/vim-eunuch'
Bundle 'tpope/vim-endwise'
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-rbenv'
Bundle 'airblade/vim-gitgutter'
Bundle 'tpope/vim-commentary'
Bundle 'mmorearty/vim-matchit'
Bundle 'duff/vim-bufonly'
Bundle 'regedarek/vim-bufexplorer'
Bundle 'vim-scripts/bufkill.vim'
Bundle 'mattn/webapi-vim'
Bundle 'mattn/gist-vim'
Bundle 'chriskempson/base16-vim'
Bundle 'bling/vim-airline'
Bundle 'koron/nyancat-vim'
Bundle 'jiangmiao/auto-pairs'
Bundle 'majutsushi/tagbar'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BASIC EDITING CONFIGURATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set hidden " allow unsaved background buffers and remember marks/undo for them
set history=700 " remember more commands and search history
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set noswapfile " No swap files when editing please
set autoread " Set to auto read when a file is changed from the outside
set expandtab shiftwidth=2 " set tab
set softtabstop=2 tabstop=2 " set tab
set autoindent
set laststatus=2
set showmatch
let g:ruby_path = system('echo $HOME/.rbenv/shims')
set nofoldenable " disable folding
set clipboard+=unnamed
set incsearch
set hlsearch
set ignorecase smartcase " make searches case-sensitive only if they contain upper-case characters
set cursorline
set number
set switchbuf=useopen
set numberwidth=5
set winwidth=79
set t_ti= t_te= " Prevent Vim from clobbering the scrollback buffer. See
set scrolloff=3 " keep more context when scrolling off the end of a buffer
set backup " Store temporary files in a central spot
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set grepprg=ack
set tags=./tags;
set noesckeys
set ttimeout
set ttimeoutlen=1
set timeoutlen=500
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set showcmd " display incomplete commands
syntax on
set wildmode=longest,list " use emacs-style tab completion when selecting files, etc
set wildignore+=*.o,*.png,*.gif,*.obj
set wildignore+=.git,*/public/*,*/tmp/*
set wildignore+=*.so,*.swp,*.zip " MacOSX/Linux
set wildmenu " make tab completion for files/buffers act like bash
let mapleader=","
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM AUTOCMDS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup vimrcEx
" Clear all autocmds in the group
autocmd!
autocmd FileType text setlocal textwidth=78
" 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
"for ruby, autoindent with two spaces, always expand tabs
autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et
autocmd BufEnter *.rb :Rooter
autocmd BufEnter *.erb :Rooter
autocmd! BufRead,BufNewFile *.sass setfiletype sass
autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:&gt;
autocmd BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:&gt;
" Indent p tags
autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
" Don't syntax highlight markdown because it's often wrong
autocmd! FileType mkd setlocal syn=off
" Unbind <enter> nohl behaviour on quickfix
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
autocmd CmdwinEnter * nnoremap <buffer> <CR> <CR>
" Detect snippets
autocmd BufNewFile,BufRead *_spec.rb :UltiSnipsAddFiletypes spec
autocmd BufNewFile,BufRead *.html.erb :UltiSnipsAddFiletypes eruby
" Remember the current 'foldmethod' so that it can be restored after a
" diff by the Nodiff or Undiff command.
au BufWinEnter * if &fdm != "diff" | let b:fdm = &fdm | endif
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" COLOR
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set t_Co=256
set background=dark
colorscheme base16-default
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" STATUS LINE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MISC KEY MAPS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <silent> <F1> :BufExplorer<CR>
map <silent> <F2> :Gstatus<CR>
map <silent> <F7> :s/:\([^ ]*\)\(\s*\)=>/\1:/g<CR>
map <space> :
imap jj <Esc>
nmap zz v$h
map <silent> rr :NERDTreeToggle<CR>
nmap <leader>b :Gbrowse<CR>
nmap <silent> <leader>d :BufOnly<CR>
nmap <silent> ff :BD<CR>
nmap <S-j> <<
nmap <S-k> >>
vnoremap < <gv
vnoremap > >gv
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
imap <c-c> <esc>
map <leader>p :bp<CR>
map <leader>n :bp<CR>
nnoremap <CR> :nohlsearch<CR>
map <leader>ny :Nyancat2<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ARROW KEYS ARE UNACCEPTABLE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <Left> <Nop>
map <Right> <Nop>
map <Up> <Nop>
map <Down> <Nop>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" OPEN FILES IN DIRECTORY OF CURRENT FILE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
map <leader>v :view %%
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TODO list
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! Todo()
:e ~/Dropbox/todo.markdown
endfunction
:command! Todo :call Todo()
:map <leader>tl :call Todo()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PROMOTE VARIABLE TO RSPEC LET
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! PromoteToLet()
:normal! dd
" :exec '?^\s*it\>'
:normal! P
:.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/
:normal ==
endfunction
:command! PromoteToLet :call PromoteToLet()
:map <leader>l :PromoteToLet<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUNNING TESTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <leader>t :call RunTestFile()<cr>
map <leader>T :call RunNearestTest()<cr>
map <leader>a :call RunTests('spec')<cr>
function! RunTestFile(...)
if a:0
let command_suffix = a:1
else
let command_suffix = ""
endif
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\)$') != -1
if in_test_file
call SetTestFile()
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file . command_suffix)
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number . " -b")
endfunction
function! SetTestFile()
let t:grb_test_file=@%
endfunction
function! RunTests(filename)
:w
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
if match(a:filename, '\.feature$') != -1
exec ":!script/features " . a:filename
else
if filereadable("script/test")
exec ":!script/test " . a:filename
elseif filereadable("Gemfile")
exec ":!rspec " . a:filename
else
exec ":!rspec --format Fuubar --color " . a:filename
end
end
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGINS SETTINGS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Surround
vmap s S
" Gist-vim
let g:gist_clip_command = 'pbcopy'
let g:gist_post_private = 1
let g:gist_detect_filetype = 1
let g:gist_show_privates = 1
let g:gist_get_multiplefile = 1
" Ctrlp.vim
nnoremap <leader>r :CtrlPMRU<cr>
let g:ctrlp_custom_ignore = {
\ 'file': '\v\.(exe|so|dll|log|gif|jpg|jpeg|png)$'
\ }
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_map = '<c-p>'
let g:ctrlp_mruf_relative = 1
let g:ctrlp_mruf_exclude = '\v\.git/(MERGE_MSG|rebase-merge|COMMIT_EDITMSG|PULLREQ_EDITMSG|index)'
let g:ctrlp_working_path_mode = 0
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_mruf_last_entered = 1
let g:ctrlp_prompt_mappings = {
\ 'PrtSelectMove("j")': ['<s-j>', '<down>'],
\ 'PrtSelectMove("k")': ['<s-k>', '<up>'],
\ 'CreateNewFile()': ['<s-n>'],
\ 'ToggleFocus()': ['<tab>'],
\ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-j>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-k>', '<c-down>'],
\ 'MarkToOpen()': ['<s-l>'],
\ 'OpenMulti()': ['<s-D>'],
\ }
let g:ctrlp_open_new_file = 0
let g:ctrlp_open_multi = 'vr'
let g:ctrlp_arg_map = 0
let g:ctrlp_jump_to_buffer = 1
let g:ctrlp_dotfiles = 0
let g:ctrlp_match_window_reversed = 0
set nocompatible " be iMproved
highlight clear SignColumn
" Airline
let g:airline_enable_fugitive=1
let g:airline_left_sep = ''
let g:airline_right_sep=''
let g:airline_theme='dark'
" TEST
" Ctags
"
" Disable tab completion
set cpt-=t
"
" On enter update/create tags
autocmd VimEnter * call UpdateOrCreateTagsFile()
" On write just update tags of this file
autocmd BufWritePost *.rb call writefile(split(system("sort -u <(touch tags && grep -v " . expand('%:%') . " tags) <(ctags --language-force=ruby -u -f - " . shellescape(expand('%:%')) . " | grep " . expand('%:r') . ")"),"\n"),"tags")
" Create tagsfile (if it doesn't exist)
" or update tags file if it is too old
" currently doesn't handle same-name classes well ...
fun! UpdateOrCreateTagsFile()
let mtime_tags = getftime("tags")
let mtime_gemfile = getftime("Gemfile.lock")
if mtime_gemfile > 0 && (mtime_tags == -1 || mtime_gemfile > mtime_tags)
echom "Generating tags as Gemfile.lock is newer than tags"
let tempfile = tempname()
call writefile(["#!/bin/bash","ctags --language-force=ruby -R -u -f tags", "rm $0"], tempfile)
silent! execute ":!bash " . tempfile . " &"
endif
endfun
nmap <F8> :TagbarToggle<CR>
let g:tagbar_type_ruby = {
\ 'kinds' : [
\ 'm:modules',
\ 'c:classes',
\ 'd:describes',
\ 'C:contexts',
\ 'f:methods',
\ 'F:singleton methods'
\ ]
\ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment