Skip to content

Instantly share code, notes, and snippets.

@robsonmarques
Last active December 19, 2015 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robsonmarques/5948464 to your computer and use it in GitHub Desktop.
Save robsonmarques/5948464 to your computer and use it in GitHub Desktop.
.vimrc
set nocompatible " Must come first because it changes other options.
" Manage the runtime path with Pathogen.
silent! call pathogen#runtime_append_all_bundles()
silent! call pathogen#helptags()
syntax enable " Turn on syntax highlighting.
filetype plugin indent on " Turn on file type detection.
set cc=80
set background=dark
colorscheme solarized
set showcmd " Display incomplete commands.
set showmode " Display the mode you're in.
set backspace=indent,eol,start " Intuitive backspacing.
set hidden " Handle multiple buffers better.
set wildmenu " Enhanced command line completion.
set wildmode=list:longest " Complete files like a shell.
set complete-=i " Don't look in included files.
set ignorecase " Case-insensitive searching.
set smartcase " But case-sensitive if expression contains a capital letter.
set number " Show absolute line numbers (cf. relativenumber).
set ruler " Show cursor position.
set laststatus=2 " Always show a status line.
set incsearch " Highlight matches as you type.
set hlsearch " Highlight matches.
set wrap " Turn on line wrapping.
set scrolloff=3 " Show 3 lines of context around the cursor.
set display+=lastline " Display as much as possibe of a window's last line.
set shiftwidth=2 "
set tabstop=2 " Tabs and spaces.
set expandtab "
set title " Set the terminal's title
set visualbell " No beeping.
set nobackup " No backups.
set nowritebackup " No backups.
set noswapfile " No swap files; more hassle than they're worth.
set undodir^=~/.vim/undo " Set .un~ files directory
set tildeop " Make tilde command behave like an operator.
set shortmess=atI " Avoid unnecessary hit-enter prompts.
set noequalalways " Resize windows as little as possible.
set autoread " Automatically re-read files changed outside Vim.
set notimeout " Don't time out partially entered mapped key sequences.
set ttimeout " But do time out key codes.
set tags=.git/tags,tags " Look for tags in .git/
set clipboard=unnamed " Use OS clipboard by default.
set cpo+=J " Two spaces delimit my sentences.
set list
set listchars=tab:\ \ ,trail:·
" Remove trailing White Space on write
autocmd BufWritePre * :%s/\s\+$//e
" TODO: include remove eof blank lines :%s#\($\n\s*\)\+\%$##
" Directory of current file.
cnoremap %% <C-R>=expand("%:h")."/"<CR>
" Clear the search buffer when hitting return
nnoremap <cr> :nohlsearch<cr>
" RSpec
map <Leader>r :call RunTest()<CR>
map <Leader>R :call RunNearestTest()<CR>
function! RunTest()
call RunTestFile(FindTestFile())
endfunction
function! RunNearestTest()
call RunTestFile(FindTestFile() . ':' . line('.'))
endfunction
function! FindTestFile()
let current_file = expand("%")
let spec_file = current_file
if match(current_file, '_spec.rb$') == -1
let spec_file = substitute(spec_file, '^app/', '', '')
let spec_file = substitute(spec_file, '.rb$', '_spec.rb', '')
let spec_file = 'spec/' . spec_file
endif
return spec_file
endfunction
function! RunTestFile(filename)
write
if filereadable('bin/rspec')
exec ":!bin/rspec --format documentation " . a:filename
else
exec ":!bundle exec rspec --format documentation " . a:filename
endif
endfunction
cmap w!! %!sudo tee > /dev/null %
function! TabOrComplete()
if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
return "\<C-N>"
else
return "\<Tab>"
endif
endfunction
inoremap <Tab> <C-R>=TabOrComplete()<CR>
set dictionary="/usr/dict/words"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment