Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 395 lines (335 sloc) 13.858 kb
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
1 " -----------------------------------------------------------------------------
2 " | VIM Settings |
3 " | (see gvimrc for gui vim settings) |
4 " | |
5 " | Some highlights: |
6 " | jj = <esc> Very useful for keeping your hands on the home row |
7 " | ,n = toggle NERDTree off and on |
8 " | |
9 " | ,f = fuzzy find all files |
10 " | ,b = fuzzy find in all buffers |
11 " | |
12 " | hh = inserts '=>' |
13 " | aa = inserts '@' |
14 " | |
15 " | ,h = new horizontal window |
16 " | ,v = new vertical window |
17 " | |
18 " | ,i = toggle invisibles |
19 " | |
20 " | enter and shift-enter = adds a new line after/before the current line |
21 " | |
22 " | :call Tabstyle_tabs = set tab to real tabs |
23 " | :call Tabstyle_spaces = set tab to 2 spaces |
24 " | |
25 " | Put machine/user specific settings in ~/.vimrc.local |
26 " -----------------------------------------------------------------------------
27
28
29 set nocompatible
30
31
32 " Tabs ************************************************************************
33 "set sta " a <Tab> in an indent inserts 'shiftwidth' spaces
34
35 function! Tabstyle_tabs()
36 " Using 4 column tabs
37 set softtabstop=4
38 set shiftwidth=4
39 set tabstop=4
40 set noexpandtab
41 autocmd User Rails set softtabstop=4
42 autocmd User Rails set shiftwidth=4
43 autocmd User Rails set tabstop=4
44 autocmd User Rails set noexpandtab
45 endfunction
46
47 function! Tabstyle_spaces()
48 " Use 2 spaces
49 set softtabstop=2
50 set shiftwidth=2
51 set tabstop=2
52 set expandtab
53 endfunction
54
55 call Tabstyle_spaces()
56
57
58 " Indenting *******************************************************************
59 set ai " Automatically set the indent of a new line (local to buffer)
60 set si " smartindent (local to buffer)
61
62
63 " Scrollbars ******************************************************************
64 set sidescrolloff=2
65 set numberwidth=4
66
67
68 " Windows *********************************************************************
69 set equalalways " Multiple windows, when created, are equal in size
f7eb721 Trying to fix opening in vsplit by default
jamesmartin authored
70 set splitright
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
71
9244836 Cleanup of unused commented out bits and pieces
James Martin authored
72 " Wildmenu stuff
3fe60a1 Added sweet buffer menu stuff
jamesmartin authored
73 set wildchar=<Tab> wildmenu wildmode=full
74
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
75 "Vertical split then hop to new buffer
76 :noremap ,v :vsp^M^W^W<cr>
77 :noremap ,h :split^M^W^W<cr>
78
a84a7f3 Removed Peepopen plugin and fixed mapping definition
James Martin authored
79 " Professor VIM says '87% of users prefer jj over esc', jj abrams disagrees
80 let mapleader = ","
81 imap jj <Esc>
82 imap uu _
83 imap hh =>
84 imap aa @
85 " JM - useful to be able to toggle wrapping when writing prose
86 nnoremap <leader>w :set wrap<CR>
87 nnoremap <leader>W :set nowrap<CR>
88 " Open file under cursor in quicklist
89 nnoremap ,o :.cc<CR>
90 " Toggle spell checking with <leader>s
91 nmap <silent> <leader>s :set spell!<CR>
92 " Set region to British English
93 set spelllang=en_gb
94
be4b4b0 Tweaked some settings for sanity
jamesmartin authored
95 "Moving around windows more easily
96 nnoremap <C-h> <C-w>h
97 nnoremap <C-j> <C-w>j
98 nnoremap <C-k> <C-w>k
99 nnoremap <C-l> <C-w>l
100
de8e67c Resizing windows
James Martin authored
101 " Resizing windows
102 nmap <s-l> :3wincmd <<cr>
103 nmap <s-h> :3wincmd ><cr>
104 nmap <s-k> :3wincmd +<cr>
105 nmap <s-j> :3wincmd -<cr>
be4b4b0 Tweaked some settings for sanity
jamesmartin authored
106
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
107 " Searching *******************************************************************
108 set hlsearch " highlight search
109 set incsearch " incremental search, search as you type
110 set ignorecase " Ignore case when searching
111 set smartcase " Ignore case when searching lowercase
be4b4b0 Tweaked some settings for sanity
jamesmartin authored
112 set gdefault
59411bd Wrap/nowrap mappings for vim
jamesmartin authored
113 " JM CTRL-n for toggling search hilighting
114 :map <silent> <C-N> :set invhlsearch<CR>
be4b4b0 Tweaked some settings for sanity
jamesmartin authored
115 nnoremap / /\v
116 vnoremap / /\v
117 " Bracket jumping with TAB
118 nnoremap <tab> %
119 vnoremap <tab> %
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
120
928dbd2 Pathogen and Python
James Martin authored
121 call pathogen#infect()
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
122
156dd6e Cleanup and added a bunch of useful helper methods from Gary Bernhardt
James Martin authored
123 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
124 " MULTIPURPOSE TAB KEY - courtesy of Gary Bernhardt
125 " Indent if we're at the beginning of a line. Else, do completion.
126 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
127 function! InsertTabWrapper()
128 let col = col('.') - 1
129 if !col || getline('.')[col - 1] !~ '\k'
130 return "\<tab>"
131 else
132 return "\<c-p>"
133 endif
134 endfunction
135 inoremap <tab> <c-r>=InsertTabWrapper()<cr>
136 inoremap <s-tab> <c-n>
137
138 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
139 " RENAME CURRENT FILE - courtesy of Gary Bernhardt
140 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
141 function! RenameFile()
142 let old_name = expand('%')
143 let new_name = input('New file name: ', expand('%'), 'file')
144 if new_name != '' && new_name != old_name
145 exec ':saveas ' . new_name
146 exec ':silent !rm ' . old_name
147 redraw!
148 endif
149 endfunction
150 map <leader>n :call RenameFile()<cr>
151
152 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
153 " PROMOTE VARIABLE TO RSPEC LET - courtesy of Gary Bernhardt
154 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
155 function! PromoteToLet()
156 :normal! dd
157 " :exec '?^\s*it\>'
158 :normal! P
159 :.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/
160 :normal ==
161 endfunction
162 :command! PromoteToLet :call PromoteToLet()
163 :map <leader>p :PromoteToLet<cr>
164
165 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
166 " SWITCH BETWEEN TEST AND PRODUCTION CODE
167 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
168 function! OpenTestAlternate()
169 let new_file = AlternateForCurrentFile()
170 exec ':e ' . new_file
171 endfunction
172 function! AlternateForCurrentFile()
173 let current_file = expand("%")
174 let new_file = current_file
175 let in_spec = match(current_file, '^spec/') != -1
176 let going_to_spec = !in_spec
177 let in_app = match(current_file, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<views\>') != -1
178 if going_to_spec
179 if in_app
180 let new_file = substitute(new_file, '^app/', '', '')
181 end
182 let new_file = substitute(new_file, '\.rb$', '_spec.rb', '')
183 let new_file = 'spec/' . new_file
184 else
185 let new_file = substitute(new_file, '_spec\.rb$', '.rb', '')
186 let new_file = substitute(new_file, '^spec/', '', '')
187 if in_app
188 let new_file = 'app/' . new_file
189 end
190 endif
191 return new_file
192 endfunction
193 nnoremap <leader>. :call OpenTestAlternate()<cr>
194
195 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
196 " RUNNING TESTS
197 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
198 function! RunTests(filename)
199 " Write the file and run tests for the given filename
200 :w
201 :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
202 :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
203 :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
204 :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
205 :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
206 :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
207 if match(a:filename, '\.feature$') != -1
208 exec ":!script/features " . a:filename
209 else
210 if filereadable("script/test")
211 exec ":!script/test " . a:filename
212 elseif filereadable("Gemfile")
213 exec ":!bundle exec rspec --color " . a:filename
214 else
215 exec ":!rspec --color " . a:filename
216 end
217 end
218 endfunction
219
220 function! SetTestFile()
221 " Set the spec file that tests will be run for.
222 let t:grb_test_file=@%
223 endfunction
224
225 function! RunTestFile(...)
226 if a:0
227 let command_suffix = a:1
228 else
229 let command_suffix = ""
230 endif
231
232 " Run the tests for the previously-marked file.
233 let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\)$') != -1
234 if in_test_file
235 call SetTestFile()
236 elseif !exists("t:grb_test_file")
237 return
238 end
239 call RunTests(t:grb_test_file . command_suffix)
240 endfunction
241
242 function! RunNearestTest()
243 let spec_line_number = line('.')
244 call RunTestFile(":" . spec_line_number . " -b")
245 endfunction
246
247 map <leader>r :call RunTestFile()<cr>
248 map <leader>R :call RunNearestTest()<cr>
249 map <leader>a :call RunTests('')<cr>
250 map <leader>c :w\|:!script/features<cr>
251 map <leader>w :w\|:!script/features --profile wip<cr>
252
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
253 " Colors **********************************************************************
254 set background=dark
e56bc52 Always use solarized colorscheme
James Martin authored
255 colorscheme solarized
256 syntax on
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
257
2379bf6 Make CursorLine highlighting actually work and be a different colour …
jamesmartin authored
258 " Cursor highlights ***********************************************************
259 set cursorline
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
260
261 " Status Line *****************************************************************
262 set showcmd
263 set ruler " Show ruler
156dd6e Cleanup and added a bunch of useful helper methods from Gary Bernhardt
James Martin authored
264 set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
265
266 " Line Wrapping ***************************************************************
267 set nowrap
268 set linebreak " Wrap at word
269
ac47a84 Fold settings and rubytest bindings
jamesmartin authored
270 " Folding ***************************************************************
271 set foldmethod=indent
272 set foldnestmax=10
273 set nofoldenable
274 set foldlevel=1
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
275
276 " File Stuff ******************************************************************
277 filetype plugin indent on
156dd6e Cleanup and added a bunch of useful helper methods from Gary Bernhardt
James Martin authored
278 autocmd FileType html :set filetype=xhtml
4a20a79 Updated vimrc for cpputest filetypes
jamesmartin authored
279 autocmd FileType cpp :set filetype=cpp.cpputest
280 autocmd FileType hpp :set filetype=hpp.cpputest
281 autocmd FileType c :set filetype=c.cpputest
282 autocmd FileType h :set filetype=h.cpputest
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
283
156dd6e Cleanup and added a bunch of useful helper methods from Gary Bernhardt
James Martin authored
284 " Restore cursor position
06e7133 Fixed vim color scheme for terminal and refactored bash profile with …
jamesmartin authored
285 autocmd BufReadPost *
156dd6e Cleanup and added a bunch of useful helper methods from Gary Bernhardt
James Martin authored
286 \ if line("'\"") > 0 && line("'\"") <= line("$") |
06e7133 Fixed vim color scheme for terminal and refactored bash profile with …
jamesmartin authored
287 \ exe "normal! g`\"" |
288 \ endif
289
28161a6 Vim markdown syntax highlighting
jamesmartin authored
290 augroup mkd
291 autocmd BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:&gt;
292 augroup END
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
293
9244836 Cleanup of unused commented out bits and pieces
James Martin authored
294 " Insert New Line **************************************************************
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
295 map <S-Enter> O<ESC> " awesome, inserts new line without going into insert mode
296 map <Enter> o<ESC>
297
298 " Sessions ********************************************************************
299 " Sets what is saved when you save a session
300 set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
301
302 " Misc ************************************************************************
303 set backspace=indent,eol,start
8d9b266 Relative line numbers turned out to be less useful than actual line n…
James Martin authored
304 set number " Show line numbers
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
305 set matchpairs+=<:>
306 set vb t_vb= " Turn off bell, this could be more annoying, but I'm not sure how
307
308
309 " Invisible characters *********************************************************
310 set listchars=trail:.,tab:>-,eol:$
311 set nolist
312 :noremap ,i :set list!<CR> " Toggle invisible chars
313
be4b4b0 Tweaked some settings for sanity
jamesmartin authored
314 " Long line stuff
315 set textwidth=79
316 set formatoptions=qrnl
317 set colorcolumn=85
318
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
319 " Cursor Movement *************************************************************
320 " Make cursor move by visual lines instead of file lines (when wrapping)
321 map <up> gk
322 map k gk
323 imap <up> <C-o>gk
324 map <down> gj
325 map j gj
326 imap <down> <C-o>gj
327 map E ge
328
329 " Ruby stuff ******************************************************************
330 "compiler ruby " Enable compiler support for ruby
331 "map <F5> :!ruby %<CR>
332
333 " Omni Completion *************************************************************
334 autocmd FileType html :set omnifunc=htmlcomplete#CompleteTags
335 autocmd FileType python set omnifunc=pythoncomplete#Complete
336 autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
337 autocmd FileType css set omnifunc=csscomplete#CompleteCSS
338 autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
339 autocmd FileType php set omnifunc=phpcomplete#CompletePHP
340 autocmd FileType c set omnifunc=ccomplete#Complete
341 " May require ruby compiled in
342 autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
343
59411bd Wrap/nowrap mappings for vim
jamesmartin authored
344 autocmd FileType c set makeprg=scons\ \check
345 autocmd FileType ruby set makeprg=rake
346
347 " JM the JumpToError function acts weird without this
348 set switchbuf=useopen
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
349
350 " -----------------------------------------------------------------------------
351 " | Plug-ins |
352 " -----------------------------------------------------------------------------
353
354 " NERDTree ********************************************************************
355 :noremap ,n :NERDTreeToggle<CR>
356
357 " User instead of Netrw when doing an edit /foobar
358 let NERDTreeHijackNetrw=1
359
360 " Single click for everything
361 let NERDTreeMouseMode=1
362
037baf8 Ack/Ag config
James Martin authored
363 " Ack/Ag
364 let g:ackprg = 'ag --nogroup --nocolor --column'
365
c83420e Added vim_files. Link to vimrc and gvimrc.
jamesmartin authored
366 " -----------------------------------------------------------------------------
367 " | OS Specific |
368 " | (GUI stuff goes in gvimrc) |
369 " -----------------------------------------------------------------------------
370
371 " Mac *************************************************************************
372 "if has("mac")
373 ""
374 "endif
375
376 " Windows *********************************************************************
377 "if has("gui_win32")
378 ""
379 "endif
380
381 " -----------------------------------------------------------------------------
382 " | Host specific |
383 " -----------------------------------------------------------------------------
384 if filereadable(expand("~/.vimrc.local"))
385 source ~/.vimrc.local
386 endif
387
388 "if hostname() == "foo"
389 " do something
390 "endif
d944e67 Ctrl-p
James Martin authored
391 "
392 " CTRL-P
393 "
394 set runtimepath^=~/.vim/bundle/ctrlp.vim
Something went wrong with that request. Please try again.