Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 295 lines (239 sloc) 8.546 kb
d9da825 @garybernhardt Initial commit
authored
1 " An example for a vimrc file.
2 "
3 " Maintainer: Bram Moolenaar <Bram@vim.org>
4 " Last change: 2002 Sep 19
5 "
6 " To use it, copy it to
7 " for Unix and OS/2: ~/.vimrc
8 " for Amiga: s:.vimrc
9 " for MS-DOS and Win32: $VIM\_vimrc
10 " for OpenVMS: sys$login:.vimrc
11
12 " When started as "evim", evim.vim will already have done these settings.
13 if v:progname =~? "evim"
14 finish
15 endif
16
17 " Use Vim settings, rather then Vi settings (much better!).
18 " This must be first, because it changes other options as a side effect.
19 set nocompatible
20
21 " Allow backgrounding buffers without writing them, and remember marks/undo
22 " for backgrounded buffers
23 set hidden
24
25 " Remember more commands and search history
26 set history=1000
27
28 " Make tab completion for files/buffers act like bash
29 set wildmenu
30 set wildmode=list:longest
31
32 " Make searches case-sensitive only if they contain upper-case characters
33 set ignorecase
34 set smartcase
35
36 " Keep more context when scrolling off the end of a buffer
37 set scrolloff=3
38
39 " Store temporary files in a central spot
40 set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
41 set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
42
43 " allow backspacing over everything in insert mode
44 set backspace=indent,eol,start
45
46 if has("vms")
47 set nobackup " do not keep a backup file, use versions instead
48 else
49 set backup " keep a backup file
50 endif
51 set history=50 " keep 50 lines of command line history
52 set ruler " show the cursor position all the time
53 set showcmd " display incomplete commands
54 set incsearch " do incremental searching
55
56 " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
57 " let &guioptions = substitute(&guioptions, "t", "", "g")
58
59 " Don't use Ex mode, use Q for formatting
60 map Q gq
61
62 " This is an alternative that also works in block mode, but the deleted
63 " text is lost and it only works for putting the current register.
64 "vnoremap p "_dp
65
66 " Switch syntax highlighting on, when the terminal has colors
67 " Also switch on highlighting the last used search pattern.
68 if &t_Co > 2 || has("gui_running")
69 syntax on
70 set hlsearch
ea3ed4d @garybernhardt Set GUI font to Monaco 12pt
authored
71 set guifont=Monaco:h12
d9da825 @garybernhardt Initial commit
authored
72 endif
73
74 " Only do this part when compiled with support for autocommands.
75 if has("autocmd")
76
77 " Enable file type detection.
78 " Use the default filetype settings, so that mail gets 'tw' set to 72,
79 " 'cindent' is on in C files, etc.
80 " Also load indent files, to automatically do language-dependent indenting.
81 filetype plugin indent on
82
83 " Put these in an autocmd group, so that we can delete them easily.
84 augroup vimrcEx
85 au!
86
87 " For all text files set 'textwidth' to 78 characters.
88 autocmd FileType text setlocal textwidth=78
89
90 " When editing a file, always jump to the last known cursor position.
91 " Don't do it when the position is invalid or when inside an event handler
92 " (happens when dropping a file on gvim).
93 autocmd BufReadPost *
94 \ if line("'\"") > 0 && line("'\"") <= line("$") |
95 \ exe "normal g`\"" |
96 \ endif
97
98 augroup END
99
100 else
101
102 set autoindent " always set autoindenting on
103
104 endif " has("autocmd")
105
106
107 " GRB: sane editing configuration"
108 set expandtab
109 set tabstop=4
110 set shiftwidth=4
111 set softtabstop=4
112 set autoindent
113 " set smartindent
114 set laststatus=2
115 set showmatch
116 set incsearch
117
118 " GRB: wrap lines at 78 characters
119 set textwidth=78
120
121 " GRB: highlighting search"
122 set hls
123
124 if has("gui_running")
125 " GRB: set font"
126 ":set nomacatsui anti enc=utf-8 gfn=Monaco:h12
127
128 " GRB: set window size"
129 :set lines=100
130 :set columns=157
131
132 " GRB: highlight current line"
133 :set cursorline
134 endif
135
136 " GRB: set the color scheme
137 if !has("gui_running")
9219fcd @garybernhardt Added my own vim color scheme (modified version of slate)
authored
138 :color grb2
d9da825 @garybernhardt Initial commit
authored
139 endif
140
141 " GRB: add pydoc command
20b2475 @garybernhardt Removed trailing whitespace in .vimrc
authored
142 :command! -nargs=+ Pydoc :call ShowPydoc("<args>")
143 function! ShowPydoc(module, ...)
144 let fPath = "/tmp/pyHelp_" . a:module . ".pydoc"
145 :execute ":!pydoc " . a:module . " > " . fPath
146 :execute ":sp ".fPath
147 endfunction
d9da825 @garybernhardt Initial commit
authored
148
149 " GRB: Always source python.vim for Python files
150 au FileType python source ~/.vim/scripts/python.vim
151
152 " GRB: Use custom python.vim syntax file
153 au! Syntax python source ~/.vim/syntax/python.vim
154 let python_highlight_all = 1
155 let python_slow_sync = 1
156
157 " GRB: use emacs-style tab completion when selecting files, etc
158 set wildmode=longest,list
159
160 " GRB: Put useful info in status line
161 :set statusline=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
162 :hi User1 term=inverse,bold cterm=inverse,bold ctermfg=red
163
164 " GRB: clear the search buffer when hitting return
165 :nnoremap <CR> :nohlsearch<CR>/<BS>
166
a6543a3 @garybernhardt Moved snippet completion to semicolon in vim
authored
167 " Remap the tab key to do autocompletion or indentation depending on the
168 " context (from http://www.vim.org/tips/tip.php?tip_id=102)
20b2475 @garybernhardt Removed trailing whitespace in .vimrc
authored
169 function! InsertTabWrapper()
170 let col = col('.') - 1
171 if !col || getline('.')[col - 1] !~ '\k'
172 return "\<tab>"
173 else
a6543a3 @garybernhardt Moved snippet completion to semicolon in vim
authored
174 return "\<c-p>"
20b2475 @garybernhardt Removed trailing whitespace in .vimrc
authored
175 endif
176 endfunction
a6543a3 @garybernhardt Moved snippet completion to semicolon in vim
authored
177 inoremap <tab> <c-r>=InsertTabWrapper()<cr>
178 inoremap <s-tab> <c-n>
179
180 " Use semicolon for snippets
181 let g:snippetsEmu_key = ';'
d9da825 @garybernhardt Initial commit
authored
182
183 if version >= 700
184 autocmd FileType python set omnifunc=pythoncomplete#Complete
185 let Tlist_Ctags_Cmd='~/bin/ctags'
186 endif
187
a68ddbe @garybernhardt Made :bd not close splits
authored
188 " GRB: use fancy buffer closing that doesn't close the split
189 cnoremap <expr> bd (getcmdtype() == ':' ? 'Bclose' : 'bd')
190
7e4384c @garybernhardt Added more ways to run tests in vim
authored
191 function! RunTests(target, args)
b54f0e6 @garybernhardt Made test running from vim fancier
authored
192 silent ! echo
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
193 exec 'silent ! echo -e "\033[1;36mRunning tests in ' . a:target . '\033[0m"'
7e4384c @garybernhardt Added more ways to run tests in vim
authored
194 set makeprg=scripts/tests\ --with-doctest\ -x
b54f0e6 @garybernhardt Made test running from vim fancier
authored
195 silent w
62ff89d @garybernhardt Improved test behavior in MacVim
authored
196 exec "make " . a:target . " " . a:args
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
197 endfunction
198
199 function! ClassToFilename(class_name)
200 let understored_class_name = substitute(a:class_name, '\(.\)\(\u\)', '\1_\U\2', 'g')
201 let file_name = substitute(understored_class_name, '\(\u\)', '\L\1', 'g')
202 return file_name
203 endfunction
204
205 function! ModuleTestPath()
206 let file_path = @%
207 let components = split(file_path, '/')
208 let path_without_extension = substitute(file_path, '\.py$', '', '')
209 let path_without_bb_prefix = join(split(path_without_extension, '/')[1:], '/')
210 let test_path = 'tests/unit/' . path_without_bb_prefix
211 return test_path
212 endfunction
213
214 function! NameOfCurrentClass()
215 let save_cursor = getpos(".")
216 normal $<cr>
217 call PythonDec('class', -1)
218 let line = getline('.')
219 call setpos('.', save_cursor)
220 let match_result = matchlist(line, ' *class \+\(\w\+\)')
221 let class_name = ClassToFilename(match_result[1])
222 return class_name
223 endfunction
224
4789e37 @garybernhardt Made ,t jump to the tests for the current class
authored
225 function! TestFileForCurrentClass()
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
226 let class_name = NameOfCurrentClass()
227 let test_file_name = ModuleTestPath() . '/test_' . class_name . '.py'
228 return test_file_name
229 endfunction
230
219dea6 @garybernhardt Made ,m run tests for current file instead of current class
authored
231 function! TestModuleForCurrentFile()
232 let test_path = ModuleTestPath()
233 let test_module = substitute(test_path, '/', '.', 'g')
234 return test_module
235 endfunction
236
7e4384c @garybernhardt Added more ways to run tests in vim
authored
237 function! RunTestsForFile(args)
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
238 if @% =~ 'test_'
7e4384c @garybernhardt Added more ways to run tests in vim
authored
239 call RunTests('%', a:args)
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
240 else
219dea6 @garybernhardt Made ,m run tests for current file instead of current class
authored
241 let test_file_name = TestModuleForCurrentFile()
7e4384c @garybernhardt Added more ways to run tests in vim
authored
242 call RunTests(test_file_name, a:args)
f03120a @garybernhardt Added proper handling of all tests passing in vim
authored
243 endif
b54f0e6 @garybernhardt Made test running from vim fancier
authored
244 endfunction
245
7e4384c @garybernhardt Added more ways to run tests in vim
authored
246 function! RunAllTests(args)
b54f0e6 @garybernhardt Made test running from vim fancier
authored
247 silent ! echo
248 silent ! echo -e "\033[1;36mRunning all unit tests\033[0m"
249 set makeprg=scripts/tests\ --with-doctest\ -x\ -v
250 silent w
7e4384c @garybernhardt Added more ways to run tests in vim
authored
251 exec "make! tests.unit " . a:args
252 endfunction
253
254 function! JumpToError()
255 if getqflist() != []
c6bd76d @garybernhardt Added green and red bars when running tests in vim
authored
256 for error in getqflist()
257 if error['valid']
258 break
259 endif
260 endfor
261 let error_message = substitute(error['text'], '^ *', '', 'g')
262 silent cc!
ff7824a @garybernhardt Made green/red test result bars work in macvim
authored
263 hi TestsFail ctermfg=white ctermbg=red guibg=red
c6bd76d @garybernhardt Added green and red bars when running tests in vim
authored
264 echohl TestsFail
61f3714 @garybernhardt Tweaked red/green test status bars in vim
authored
265 echo " "
c6bd76d @garybernhardt Added green and red bars when running tests in vim
authored
266 echohl
61f3714 @garybernhardt Tweaked red/green test status bars in vim
authored
267 echo error_message
7e4384c @garybernhardt Added more ways to run tests in vim
authored
268 else
ff7824a @garybernhardt Made green/red test result bars work in macvim
authored
269 hi TestsPass ctermfg=white ctermbg=green guibg=green
c6bd76d @garybernhardt Added green and red bars when running tests in vim
authored
270 echohl TestsPass
61f3714 @garybernhardt Tweaked red/green test status bars in vim
authored
271 echo " "
c6bd76d @garybernhardt Added green and red bars when running tests in vim
authored
272 echohl
61f3714 @garybernhardt Tweaked red/green test status bars in vim
authored
273 echo "All tests passed"
7e4384c @garybernhardt Added more ways to run tests in vim
authored
274 endif
b54f0e6 @garybernhardt Made test running from vim fancier
authored
275 endfunction
e398051 @garybernhardt Made ,m run tests in Python files in vim
authored
276
4789e37 @garybernhardt Made ,t jump to the tests for the current class
authored
277 function! JumpToTestsForClass()
278 exec 'e ' . TestFileForCurrentClass()
279 endfunction
280
6828f02 @garybernhardt Made ,m run tests and jump to first error immediately in vim
authored
281 let mapleader=","
62ff89d @garybernhardt Improved test behavior in MacVim
authored
282 nnoremap <leader>m :call RunTestsForFile('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
7e4384c @garybernhardt Added more ways to run tests in vim
authored
283 nnoremap <leader>M :call RunTestsForFile('')<cr>
62ff89d @garybernhardt Improved test behavior in MacVim
authored
284 nnoremap <leader>a :call RunAllTests('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
7e4384c @garybernhardt Added more ways to run tests in vim
authored
285 nnoremap <leader>A :call RunAllTests('')<cr>
4789e37 @garybernhardt Made ,t jump to the tests for the current class
authored
286 nnoremap <leader>t :call JumpToTestsForClass()<cr>
3de8b20 @garybernhardt Made ,, switch to last buffer (used to be ,o)
authored
287 nnoremap <leader><leader> <c-^>
8ae7a06 @garybernhardt Made vim use nose when doing :make
authored
288
4eb8860 @garybernhardt Enabled current line highlighting in vim
authored
289 " highlight current line
cb168a9 @garybernhardt Turned off cursorcolumn in vim
authored
290 set cursorline
3e4ba75 @garybernhardt Made the highlighted line in vim have a black background
authored
291 hi CursorLine cterm=NONE ctermbg=black
292
339b8fa @garybernhardt Set cmdheight to 2 in vim
authored
293 set cmdheight=2
294
Something went wrong with that request. Please try again.