2012-11-16 06:05:17 +00:00
|
|
|
let mapleader=","
|
|
|
|
|
2012-05-19 19:56:52 +00:00
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" PLUGINS
|
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
2012-11-06 01:12:34 +00:00
|
|
|
call pathogen#infect()
|
2012-05-19 19:56:52 +00:00
|
|
|
call pathogen#helptags()
|
|
|
|
|
2014-06-25 16:41:16 +00:00
|
|
|
" # selecta
|
2014-05-17 19:31:36 +00:00
|
|
|
" Run a given vim command on the results of fuzzy selecting from a given shell
|
|
|
|
" command. See usage below.
|
|
|
|
function! SelectaCommand(choice_command, selecta_args, vim_command)
|
|
|
|
try
|
|
|
|
silent let selection = system(a:choice_command . " | selecta " . a:selecta_args)
|
|
|
|
catch /Vim:Interrupt/
|
|
|
|
" Swallow the ^C so that the redraw below happens; otherwise there will be
|
|
|
|
" leftovers from selecta on the screen
|
|
|
|
redraw!
|
|
|
|
return
|
|
|
|
endtry
|
|
|
|
redraw!
|
|
|
|
exec a:vim_command . " " . selection
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Find all files in all non-dot directories starting in the working directory.
|
|
|
|
" Fuzzy select one of those. Open the selected file with :e.
|
|
|
|
nnoremap <leader>ff :call SelectaCommand("find * -type f", "", ":e")<cr>
|
2013-04-20 18:00:26 +00:00
|
|
|
|
2013-08-30 17:15:57 +00:00
|
|
|
" # NERDtree
|
|
|
|
nmap <leader>d :NERDTreeToggle<CR>
|
|
|
|
nmap <leader>f :NERDTreeFind<CR>
|
|
|
|
|
2013-04-21 17:48:27 +00:00
|
|
|
" # gist-vim
|
|
|
|
let g:gist_detect_filetype = 1
|
|
|
|
let g:gist_open_browser_after_post = 1
|
|
|
|
let g:gist_show_privates = 1
|
|
|
|
let g:gist_post_private = 1
|
|
|
|
|
2014-06-25 16:41:16 +00:00
|
|
|
" # c-tags
|
|
|
|
set tags+=tags;$HOME
|
|
|
|
|
2012-04-19 14:23:13 +00:00
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" BASIC EDITING CONFIGURATION
|
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
set nocompatible
|
|
|
|
" allow unsaved background buffers and remember marks/undo for them
|
|
|
|
set hidden
|
|
|
|
set history=10000
|
|
|
|
set expandtab
|
2012-11-04 23:22:31 +00:00
|
|
|
set tabstop=2
|
|
|
|
set shiftwidth=2
|
|
|
|
set softtabstop=2
|
2011-04-15 18:44:28 +00:00
|
|
|
set autoindent
|
2012-04-19 14:23:13 +00:00
|
|
|
set laststatus=2
|
|
|
|
set showmatch
|
|
|
|
set incsearch
|
2013-04-20 18:00:26 +00:00
|
|
|
set dictionary+=/usr/share/dict/words
|
2013-08-30 17:11:59 +00:00
|
|
|
set clipboard=unnamed " yank and paste with the system clipboard
|
2012-05-19 19:56:52 +00:00
|
|
|
set number
|
2012-04-19 14:23:13 +00:00
|
|
|
set hlsearch
|
|
|
|
" make searches case-sensitive only if they contain upper-case characters
|
|
|
|
set ignorecase smartcase
|
|
|
|
" highlight current line
|
|
|
|
set cmdheight=2
|
|
|
|
set switchbuf=useopen
|
|
|
|
set numberwidth=5
|
|
|
|
set showtabline=2
|
|
|
|
set winwidth=79
|
|
|
|
set shell=bash
|
|
|
|
" Prevent Vim from clobbering the scrollback buffer. See
|
|
|
|
" http://www.shallowsky.com/linux/noaltscreen.html
|
|
|
|
set t_ti= t_te=
|
|
|
|
" keep more context when scrolling off the end of a buffer
|
|
|
|
set scrolloff=3
|
|
|
|
" Store temporary files in a central spot
|
|
|
|
set backup
|
|
|
|
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
|
|
|
|
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
|
|
|
|
" allow backspacing over everything in insert mode
|
|
|
|
set backspace=indent,eol,start
|
|
|
|
" display incomplete commands
|
|
|
|
set showcmd
|
|
|
|
" Enable highlighting for syntax
|
2011-04-15 18:44:28 +00:00
|
|
|
syntax on
|
2012-04-19 14:23:13 +00:00
|
|
|
" Enable file type detection.
|
|
|
|
" Use the default filetype settings, so that mail gets 'tw' set to 72,
|
|
|
|
" 'cindent' is on in C files, etc.
|
|
|
|
" Also load indent files, to automatically do language-dependent indenting.
|
|
|
|
filetype plugin indent on
|
|
|
|
" use emacs-style tab completion when selecting files, etc
|
2013-08-30 17:11:59 +00:00
|
|
|
set wildmenu
|
|
|
|
set wildmode=longest,list,full
|
2012-11-15 18:05:57 +00:00
|
|
|
colorscheme Monokai
|
2013-04-06 17:19:30 +00:00
|
|
|
set wildignore+=*/tmp/*,*/log/*,*.so,*.swp,*.zip,*/rdoc/*
|
2012-11-28 04:23:04 +00:00
|
|
|
set colorcolumn=90
|
2013-01-28 17:58:14 +00:00
|
|
|
" Show trailing whitespace
|
2013-04-21 23:36:08 +00:00
|
|
|
set list listchars=tab:»·,trail:·
|
2013-05-08 02:34:57 +00:00
|
|
|
" Adding this since the esc remap on the 'i' key had a long delay when pressed
|
|
|
|
set timeoutlen=300 ttimeoutlen=0
|
2011-04-15 18:44:28 +00:00
|
|
|
|
2013-08-16 20:50:47 +00:00
|
|
|
" Allow undo when doing back into a closed file
|
|
|
|
set undodir=$HOME/.vim/undo
|
|
|
|
set undolevels=1000
|
|
|
|
set undoreload=10000
|
|
|
|
|
2013-07-10 16:13:13 +00:00
|
|
|
" When loading text files, wrap them and don't split up words.
|
|
|
|
au BufNewFile,BufRead *.txt setlocal wrap
|
|
|
|
au BufNewFile,BufRead *.txt setlocal lbr
|
|
|
|
|
2013-05-01 13:48:08 +00:00
|
|
|
" Fix vim's background colour erase - http://snk.tuxfamily.org/log/vim-256color-bce.html
|
|
|
|
if &term =~ '256color'
|
|
|
|
" Disable Background Color Erase (BCE) so that color schemes
|
|
|
|
" work properly when Vim is used inside tmux and GNU screen.
|
|
|
|
" See also http://snk.tuxfamily.org/log/vim-256color-bce.html
|
|
|
|
set t_ut=
|
|
|
|
endif
|
|
|
|
|
2013-08-16 20:50:47 +00:00
|
|
|
" Disable arrow keys
|
|
|
|
map <up> <nop>
|
|
|
|
map <down> <nop>
|
|
|
|
map <left> <nop>
|
|
|
|
map <right> <nop>
|
|
|
|
imap <up> <nop>
|
|
|
|
imap <down> <nop>
|
|
|
|
imap <left> <nop>
|
|
|
|
imap <right> <nop>
|
|
|
|
|
2013-07-10 16:13:13 +00:00
|
|
|
" Notes and other helpers
|
|
|
|
map <Leader>bb :!bundle install<cr>
|
|
|
|
map <leader>gs :Gstatus<CR>
|
2014-06-25 16:41:16 +00:00
|
|
|
map <leader>gw :!git add . && git commit -m 'WIP'<cr>
|
2013-07-24 03:20:06 +00:00
|
|
|
map <leader>pn :sp ~/Dropbox/notes/project-notes<cr>
|
2013-07-10 16:13:13 +00:00
|
|
|
|
|
|
|
" Remove trailing whitespace on save all files.
|
|
|
|
au BufWritePre * :%s/\s\+$//e
|
|
|
|
|
2012-04-19 14:23:13 +00:00
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" 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("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
|
2011-04-15 18:44:28 +00:00
|
|
|
|
2012-04-19 14:23:13 +00:00
|
|
|
autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et
|
2012-11-04 23:22:31 +00:00
|
|
|
autocmd FileType python set sw=2 sts=2 et
|
2011-04-15 18:44:28 +00:00
|
|
|
|
2012-04-19 14:23:13 +00:00
|
|
|
" Indent p tags
|
2013-07-10 16:13:13 +00:00
|
|
|
autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
|
2012-04-19 14:23:13 +00:00
|
|
|
augroup END
|
2011-04-15 18:44:28 +00:00
|
|
|
|
2012-11-04 23:22:31 +00:00
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" STATUS LINE
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
:set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
|
|
|
|
|
2012-04-19 14:23:13 +00:00
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" MISC KEY MAPS
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
2012-11-04 23:27:39 +00:00
|
|
|
" insert an end tag with <c-e>
|
|
|
|
imap <c-e> end
|
|
|
|
|
2013-07-10 16:13:13 +00:00
|
|
|
" insert a hash rocket with <c-l>
|
2012-04-19 14:23:13 +00:00
|
|
|
imap <c-l> <space>=><space>
|
2011-04-15 18:44:28 +00:00
|
|
|
|
2013-04-20 18:00:26 +00:00
|
|
|
" Mapping ESC in insert mode and command mode to double i
|
2014-06-25 16:41:16 +00:00
|
|
|
imap ii <C-[>
|
|
|
|
cmap ii <C-[>
|
2011-04-15 18:44:28 +00:00
|
|
|
|
2012-11-17 02:52:40 +00:00
|
|
|
" suspend process
|
|
|
|
nmap <leader>z <c-z>
|
2012-11-16 05:14:27 +00:00
|
|
|
|
|
|
|
" Quickly edit/reload the vimrc file
|
2013-07-10 16:13:13 +00:00
|
|
|
nmap <silent> <leader>ev :vsp $MYVIMRC<cr>
|
2012-11-16 05:14:27 +00:00
|
|
|
nmap <silent> <leader>rv :so $MYVIMRC<cr>
|
|
|
|
|
|
|
|
" remap saving and quiting :P
|
|
|
|
nmap <leader>w :w<cr>
|
|
|
|
nmap <leader>q :q<cr>
|
|
|
|
nmap <leader>Q :q!<cr>
|
|
|
|
nmap <leader>x :x<cr>
|
2013-08-13 15:17:54 +00:00
|
|
|
:ca Wa wa
|
|
|
|
:ca WA wa
|
2012-11-16 05:14:27 +00:00
|
|
|
:ca WQ wq
|
|
|
|
:ca Wq wq
|
|
|
|
:ca W w
|
|
|
|
:ca Q q
|
|
|
|
|
2013-07-10 16:13:13 +00:00
|
|
|
command! Q q " Bind :Q to :q
|
|
|
|
command! Qall qall
|
|
|
|
" Disable Ex mode
|
|
|
|
map Q <Nop>
|
|
|
|
|
2012-11-16 06:05:17 +00:00
|
|
|
" Map ctrl-movement keys to window switching
|
|
|
|
map <c-k> <c-w><Up>
|
|
|
|
map <c-j> <c-w><Down>
|
|
|
|
map <c-l> <c-w><Right>
|
|
|
|
map <c-h> <c-w><Left>
|
|
|
|
|
2013-04-20 18:00:26 +00:00
|
|
|
" Window splitting - couldn't figure out how to remap <c-w>v & <c-w>n to <c-m>
|
|
|
|
" & <c-n>
|
|
|
|
map <leader>m :vsplit<cr>
|
|
|
|
map <leader>mm :split<cr>
|
|
|
|
|
2012-11-16 06:05:17 +00:00
|
|
|
map <leader>gg :topleft 100 :split Gemfile<cr>
|
2013-07-16 23:36:06 +00:00
|
|
|
map <leader>gr :topleft 100 :split config/routes.rb<cr>
|
2012-11-16 06:05:17 +00:00
|
|
|
|
2014-02-17 07:00:21 +00:00
|
|
|
" Map paste and nonumber
|
|
|
|
map <leader>p :set paste! paste?<cr>
|
|
|
|
map <leader>o :set number! number?<cr>
|
|
|
|
|
2012-04-19 14:23:13 +00:00
|
|
|
" Clear the search buffer (highlighting) when hitting return
|
2012-11-04 23:22:31 +00:00
|
|
|
function! MapCR()
|
|
|
|
nnoremap <cr> :nohlsearch<cr>
|
|
|
|
endfunction
|
|
|
|
call MapCR()
|
2012-04-19 14:23:13 +00:00
|
|
|
nnoremap <leader><leader> <c-^>
|
2011-04-15 18:44:28 +00:00
|
|
|
|
2012-11-05 02:33:43 +00:00
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" ABBREVIATIONS
|
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
:ab teh the
|
2014-06-25 16:41:16 +00:00
|
|
|
:ab kewyord keyword
|
|
|
|
|
2012-11-05 02:33:43 +00:00
|
|
|
|
2012-04-19 14:23:13 +00:00
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" MULTIPURPOSE TAB KEY
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
function! InsertTabWrapper()
|
|
|
|
let col = col('.') - 1
|
|
|
|
if !col || getline('.')[col - 1] !~ '\k'
|
|
|
|
return "\<tab>"
|
|
|
|
else
|
|
|
|
return "\<c-p>"
|
2011-04-15 18:44:28 +00:00
|
|
|
endif
|
2012-04-19 14:23:13 +00:00
|
|
|
endfunction
|
|
|
|
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
|
|
|
|
inoremap <s-tab> <c-n>
|
|
|
|
|
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" RENAME CURRENT FILE
|
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
function! RenameFile()
|
|
|
|
let old_name = expand('%')
|
|
|
|
let new_name = input('New file name: ', expand('%'), 'file')
|
|
|
|
if new_name != '' && new_name != old_name
|
|
|
|
exec ':saveas ' . new_name
|
|
|
|
exec ':silent !rm ' . old_name
|
|
|
|
redraw!
|
2011-04-15 18:44:28 +00:00
|
|
|
endif
|
2012-04-19 14:23:13 +00:00
|
|
|
endfunction
|
|
|
|
map <leader>n :call RenameFile()<cr>
|
|
|
|
|
2012-11-15 18:05:57 +00:00
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
2013-04-20 18:00:26 +00:00
|
|
|
" GREP SEARCH
|
2012-11-15 18:05:57 +00:00
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
2012-11-13 17:05:37 +00:00
|
|
|
function! Search()
|
|
|
|
let term = input('Grep search term: ')
|
|
|
|
if term != ''
|
2013-04-20 18:00:26 +00:00
|
|
|
exec 'Ag "' . term . '"'
|
2012-11-13 17:05:37 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
map <leader>s :call Search()<cr>
|
|
|
|
|
2012-04-19 14:23:13 +00:00
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" 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()
|
2014-05-17 19:31:36 +00:00
|
|
|
:map <leader>pl :PromoteToLet<cr>
|
2012-04-19 14:23:13 +00:00
|
|
|
|
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" RUNNING TESTS
|
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
2012-10-24 06:51:26 +00:00
|
|
|
map <leader>t :call RunTestFile()<cr>
|
|
|
|
map <leader>T :call RunNearestTest()<cr>
|
|
|
|
map <leader>a :call RunTests('')<cr>
|
|
|
|
map <leader>c :w\|:!script/features<cr>
|
2012-04-19 14:23:13 +00:00
|
|
|
|
|
|
|
function! RunTestFile(...)
|
|
|
|
if a:0
|
|
|
|
let command_suffix = a:1
|
|
|
|
else
|
|
|
|
let command_suffix = ""
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Run the tests for the previously-marked file.
|
|
|
|
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
|
2011-04-15 18:44:28 +00:00
|
|
|
|
2012-10-24 06:51:26 +00:00
|
|
|
function! SetTestFile()
|
|
|
|
" Set the spec file that tests will be run for.
|
|
|
|
let t:grb_test_file=@%
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! RunTests(filename)
|
|
|
|
" Write the file and run tests for the given 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 ":!bundle exec rspec --color " . a:filename
|
|
|
|
else
|
|
|
|
exec ":!rspec --color " . a:filename
|
|
|
|
end
|
|
|
|
end
|
|
|
|
endfunction
|
2012-11-17 02:52:40 +00:00
|
|
|
|
2013-08-16 20:50:47 +00:00
|
|
|
" Use Marked.app to preview Markdown files...
|
2014-02-17 07:00:21 +00:00
|
|
|
nnoremap <leader>pp :silent !open -a Marked.app '%:p'<cr>
|
2013-08-16 20:50:47 +00:00
|
|
|
|