Skip to content
Newer
Older
100644 337 lines (279 sloc) 8.92 KB
3e30474 @kerryb Install latest versions of everything using pathogen
authored Nov 20, 2010
1 set nocompatible
2 call pathogen#helptags()
3 call pathogen#runtime_append_all_bundles()
4 filetype plugin indent on
5 syntax on
6
7 set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
8 set guioptions-=T " no toolbar
9 set statusline=%<%f\ %h%m%r%=%-20.(line=%l,col=%c%V,totlin=%L%)\%h%m%r%=%-40(,%n%Y%)\%P%#warningmsg#%{SyntasticStatuslineFlag()}%*
10 set laststatus=2 " Always show status line.
11 set number " line numbers
12 set scrolloff=3 " More context around cursor
13 set hlsearch " highlight search matches...
14 set incsearch " ...as you type
15 set ignorecase
16 set smartcase
17 set hidden " Allow buffer switching without saving
18 set history=1000
19 set wildmode=list:longest " Shell-like behaviour for command autocompletion
20 set visualbell
21 set mousehide
22 set cf " Enable error files & error jumping.
23 set autowrite " Writes on make/shell commands
24 set ruler " Ruler on
25 set nowrap " Line wrapping off
26 set timeoutlen=500
27 let mapleader = ","
28
29 set tabstop=2
30 set smarttab
31 set shiftwidth=2
32 set autoindent
33 set expandtab
34 set backspace=start,indent,eol
99a52ab @kerryb Limit size of command-T popup
authored Nov 21, 2010
35 autocmd FileType make set noexpandtab
3e30474 @kerryb Install latest versions of everything using pathogen
authored Nov 20, 2010
36
37 runtime! plugin/matchit.vim " extends % to do/end etc
38
39 if has('gui')
40 colorscheme railscasts
41 source ~/.vim/bundle/vim-ruby-debugger/ruby_debugger.vim
42 if has("mac")
43 let g:ruby_debugger_progname = 'mvim'
44 else
45 let g:ruby_debugger_progname = 'gvim'
46 endif
47 map <Leader>dg :Rdebugger<CR>
48 map <Leader>dr :RdbTest<CR>
49 endif
50
51 if $COLORTERM == 'gnome-terminal'
52 set term=xterm-color
53 set guifont=DejaVu\ Sans\ Mono\ 10
54 else
55 set guifont=Menlo:h10
56 endif
57
58 " ,s to show trailing whitespace
59 set listchars=tab:>-,trail:·,eol:$
60 nmap <silent> <leader>s :set nolist!<CR>
61
62 " Highlight trailing whitespace
63 highlight RedundantSpaces term=standout ctermbg=red guibg=red
64 match RedundantSpaces /\s\+$\| \+\ze\t/ "\ze sets end of match so only spaces highlighted
65
66 " ,h to toggle search result highlighting
67 :noremap <silent> <leader>h :set hls!<CR>
68
69 " ,w to toggle line wrap
70 :map <silent> <Leader>w :set wrap!<CR>
71
72 " ,f to find current file in NERDTree
73 map <silent> <Leader>f :NERDTreeFind<CR>
74
75 map <Leader>r :Rake<CR>
76 map <silent> <Leader>rb :wa<CR>:RunAllRubyTests<CR>
77 map <silent> <Leader>rc :wa<CR>:RunRubyFocusedContext<CR>
78 map <silent> <Leader>rf :wa<CR>:RunRubyFocusedUnitTest<CR>
79
80 map <silent> <Leader>rr :wa<CR>:rubyf %<CR>
81
82 let g:speckyQuoteSwitcherKey = "<Leader>s'"
83 let g:speckySpecSwitcherKey = "<Leader>sx"
84 let g:speckyRunSpecKey = "<Leader>ss"
85 let g:speckyWindowType = 1
86
87 let g:ragtag_global_maps = 1
88
89 nmap <silent> <Leader>m :NERDTreeToggle<CR>
90 nmap <silent> <unique> <Leader>. :BufExplorer<CR>
91
99a52ab @kerryb Limit size of command-T popup
authored Nov 21, 2010
92 " Command-T configuration
93 let g:CommandTMaxHeight=20
94
43d8743 @kerryb Steal a bunch of NERDTree configuration from Janus
authored Nov 21, 2010
95 " A whole bunch of NERDTree configuration stolen from carlhuda's janus
96
97 let NERDTreeIgnore=['\.rbc$', '\~$']
98
c4f45a5 @kerryb Don't show NERDTree when editing a single file
authored Nov 21, 2010
99 "autocmd VimEnter * NERDTree
100 autocmd VimEnter * call s:NERDTreeIfDirectory(expand("<amatch>"))
43d8743 @kerryb Steal a bunch of NERDTree configuration from Janus
authored Nov 21, 2010
101 autocmd VimEnter * wincmd p
102 autocmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
103
104 " Disable netrw's autocmd, since we're ALWAYS using NERDTree
105 runtime plugin/netRwPlugin.vim
106 augroup FileExplorer
107 au!
108 augroup END
109
110 let g:NERDTreeHijackNetrw = 0
111
c4f45a5 @kerryb Don't show NERDTree when editing a single file
authored Nov 21, 2010
112 " If the parameter is a directory (including implicit '.'), open NERDTree
113 function s:NERDTreeIfDirectory(directory)
114 if isdirectory(a:directory) || a:directory == ""
115 NERDTree
116 endif
117 endfunction
118
43d8743 @kerryb Steal a bunch of NERDTree configuration from Janus
authored Nov 21, 2010
119 " If the parameter is a directory, cd into it
120 function s:CdIfDirectory(directory)
121 if isdirectory(a:directory)
122 call ChangeDirectory(a:directory)
123 endif
124 endfunction
125
126 " NERDTree utility function
127 function s:UpdateNERDTree(stay)
128 if exists("t:NERDTreeBufName")
129 if bufwinnr(t:NERDTreeBufName) != -1
130 NERDTree
131 if !a:stay
132 wincmd p
133 end
134 endif
135 endif
136 endfunction
137
138 " Utility functions to create file commands
139 function s:CommandCabbr(abbreviation, expansion)
140 execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
141 endfunction
142
143 function s:FileCommand(name, ...)
144 if exists("a:1")
145 let funcname = a:1
146 else
147 let funcname = a:name
148 endif
149
150 execute 'command -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '(<f-args>)'
151 endfunction
152
153 function s:DefineCommand(name, destination)
154 call s:FileCommand(a:destination)
155 call s:CommandCabbr(a:name, a:destination)
156 endfunction
157
158 " Public NERDTree-aware versions of builtin functions
159 function ChangeDirectory(dir, ...)
160 execute "cd " . a:dir
161 let stay = exists("a:1") ? a:1 : 1
162 call s:UpdateNERDTree(stay)
163 endfunction
164
165 function Touch(file)
166 execute "!touch " . a:file
167 call s:UpdateNERDTree(1)
168 endfunction
169
170 function Remove(file)
171 let current_path = expand("%")
172 let removed_path = fnamemodify(a:file, ":p")
173
174 if (current_path == removed_path) && (getbufvar("%", "&modified"))
175 echo "You are trying to remove the file you are editing. Please close the buffer first."
176 else
177 execute "!rm " . a:file
178 endif
179 endfunction
180
181 function Edit(file)
182 if exists("b:NERDTreeRoot")
183 wincmd p
184 endif
185
186 execute "e " . a:file
187
188 ruby << RUBY
189 destination = File.expand_path(VIM.evaluate(%{system("dirname " . a:file)}))
190 pwd = File.expand_path(Dir.pwd)
191 home = pwd == File.expand_path("~")
192
193 if home || Regexp.new("^" + Regexp.escape(pwd)) !~ destination
194 VIM.command(%{call ChangeDirectory(system("dirname " . a:file), 0)})
195 end
196 RUBY
197 endfunction
198
199 " Define the NERDTree-aware aliases
200 call s:DefineCommand("cd", "ChangeDirectory")
201 call s:DefineCommand("touch", "Touch")
202 call s:DefineCommand("rm", "Remove")
203 call s:DefineCommand("e", "Edit")
204
3e30474 @kerryb Install latest versions of everything using pathogen
authored Nov 20, 2010
205 " Tabular
206 vnoremap <silent> <Leader>tt :call Tabularize('/\|/')<CR>
207
208 " Folding settings
209 set foldmethod=indent "fold based on indent
210 set foldnestmax=3 "deepest fold is 3 levels
211 set nofoldenable "dont fold by default
212
213 " Jump to last cursor position when opening a file
214 " Don't do it when writing a commit log entry
215 autocmd BufReadPost * call SetCursorPosition()
216 function! SetCursorPosition()
217 if &filetype !~ 'commit\c'
218 if line("'\"") > 0 && line("'\"") <= line("$")
219 exe "normal g`\""
220 endif
221 end
222 endfunction
223
c94b3b4 @kerryb Add Conque Shell
authored Nov 21, 2010
224 " Conque Shell
225 let g:ConqueTerm_ReadUnfocused = 1
226
3a15b24 @kerryb Add ZoomWin
authored Nov 21, 2010
227 " ZoomWin configuration
228 map <Leader>z :ZoomWin<CR>
229
3e30474 @kerryb Install latest versions of everything using pathogen
authored Nov 20, 2010
230 " make Y consistent with C and D
231 nnoremap Y y$
232
233 " strip trailing whitespace
234 "autocmd BufWritePre,FileWritePre * call StripTrailingWhitespace()
235 function! StripTrailingWhitespace()
236 normal mz
237 normal Hmy
238 exec '%s/\s*$//g'
239 normal 'yz<cr>
240 normal `z
241 endfunction
242 nmap <silent> <Leader>sw :call StripTrailingWhitespace()<CR>
243
244 let g:syntastic_enable_signs=1
245 let g:syntastic_auto_loc_list=1
246
247 " Alternatives to ESC: *******************************************************
248 imap jkl <ESC>
249 imap jlk <ESC>
250 imap kjl <ESC>
251 imap klj <ESC>
252 imap lkj <ESC>
253 imap ljk <ESC>
254 imap ;l <ESC>
255
f796d82 @kerryb ,rt executes run_tags
authored Nov 22, 2010
256 map <Leader>rt :!run_tags<CR><CR>
257
3e30474 @kerryb Install latest versions of everything using pathogen
authored Nov 20, 2010
258 "define :Lorem command to dump in a paragraph of lorem ipsum
259 command! -nargs=0 Lorem :normal iLorem ipsum dolor sit amet, consectetur
260 \ adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
261 \ magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
262 \ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
263 \ irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
264 \ fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
265 \ proident, sunt in culpa qui officia deserunt mollit anim id est
266 \ laborum
267
268 function! OpenInBrowser(url)
269 if has("mac")
270 exec '!open '.a:url
271 else
272 exec '!firefox -new-tab '.a:url.' &'
273 endif
274 endfunction
275
276 " Open the Ruby ApiDock page for the word under cursor
277 function! OpenRubyDoc(keyword)
278 let url = 'http://apidock.com/ruby/'.a:keyword
279 call OpenInBrowser(url)
280 endfunction
281 noremap RB :call OpenRubyDoc(expand('<cword>'))<CR>
282
283 " Open the Rails ApiDock page for the word under cursor
284 function! OpenRailsDoc(keyword)
285 let url = 'http://apidock.com/rails/'.a:keyword
286 call OpenInBrowser(url)
287 endfunction
288 noremap RR :call OpenRailsDoc(expand('<cword>'))<CR>
289
290 " :SudoW to save file using sudo (must be already authorised, eg sudo -v)
291 command! -bar -nargs=0 SudoW :silent exe "write !sudo tee % >/dev/null"|silent edit!
292
293 " Edit routes
294 command! Rroutes :Redit config/routes.rb
295 command! RTroutes :RTedit config/routes.rb
296
297 " bracket completion routines
298 " not enabled by default - to enable put "call EnableBracketCompletion()" in
299 " vimrc.local
300 function! EnableBracketCompletion()
301 inoremap { {}<Left>
302 inoremap {<CR> {<CR>}<Esc>O
303 inoremap {{ {
304 inoremap {} {}
305 inoremap ( ()<Left>
306 inoremap (<CR> (<CR>)<Esc>O
307 inoremap (( (
308 inoremap () ()
309 inoremap [ []<Left>
310 inoremap [<CR> [<CR>]<Esc>O
311 inoremap [[ [
312 inoremap [] []
313 inoremap <expr> ) strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : ")"
314 endfunction
315
316 function! DisableBracketCompletion()
317 iunmap {
318 iunmap {<CR>
319 iunmap {{
320 iunmap {}
321 iunmap (
322 iunmap (<CR>
323 iunmap ((
324 iunmap ()
325 iunmap [
326 iunmap [<CR>
327 iunmap [[
328 iunmap []
329 iunmap <expr> )
330 endfunction
331
332 " Source a local configuration file if available.
333 if filereadable(expand("~/.vimrc.local"))
334 source ~/.vimrc.local
335 endif
336
Something went wrong with that request. Please try again.