Posted By

hoffstein on 07/30/08


Tagged

vim


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

hoffstein


Vimrc


 / Published in: Other
 

This is my vimrc.

  1. set nocompatible
  2. set backspace=indent,eol,start
  3. set nobackup
  4. set mouse=a
  5. set confirm
  6.  
  7. " Windows settings
  8. source $VIMRUNTIME/mswin.vim
  9. behave mswin
  10.  
  11. " Turn off bells and flashes
  12. set noerrorbells
  13. if has('autocmd')
  14. autocmd GUIEnter * set vb t_vb=
  15. endif
  16.  
  17. " Font and color scheme
  18. "set gfn=Consolas:h10:cANSI
  19. set gfn=Inconsolata:h10:cANSI
  20. "colorscheme fruity
  21. colorscheme wombat
  22.  
  23. " Detect filetype and use syntax highlighting
  24. filetype on
  25. filetype plugin on
  26. syntax on
  27.  
  28. " Keep a bunch of command line history
  29. set history=1000
  30.  
  31. " Save swap files centrally if possible
  32. set dir=c:\\temp
  33.  
  34. " Show the cursor position and line numbers
  35. set ruler
  36. set number
  37.  
  38. " Show incomplete commands and enable wild menu
  39. set showcmd
  40. set wildmenu
  41. set wildmode=list:longest
  42.  
  43. " Enable incremental search but don't highlight matches
  44. set incsearch
  45. set nohlsearch
  46.  
  47. " Key binding F2 to toggle search highlighting
  48. map <silent> <F2> :set invhlsearch<CR>
  49.  
  50. " Smart case sensitivity
  51. set ignorecase
  52. set smartcase
  53.  
  54. " Use spaces instead of tabs
  55. set shiftwidth=4
  56. set tabstop=4
  57. set softtabstop=4
  58. set expandtab
  59.  
  60. "Enabled auto-indenting
  61. set autoindent
  62. set smartindent
  63. filetype plugin indent on
  64.  
  65. " Hide toolbar and menubar
  66. set guioptions-=T
  67. set guioptions-=m
  68.  
  69. " Leave some space at the bottom
  70. set scrolloff=2
  71.  
  72. " Show matching brace
  73. set showmatch
  74.  
  75. " Use Windows clipboard
  76. set clipboard+=unnamed
  77.  
  78. " Set default window size
  79. set lines=50 columns=100
  80.  
  81. " Don't wrap lines
  82. set nowrap
  83.  
  84. " Speed optimizations
  85. set lz
  86. set ttyfast
  87.  
  88. " Automatically set current directory to file's location
  89. set autochdir
  90.  
  91. " Permit changing buffers without saving
  92. set hidden
  93.  
  94. " Folding
  95. set foldmethod=marker
  96.  
  97. " Show tabs and trailing spaces so I can remove them
  98. set list
  99. set listchars=tab:»·,trail:·
  100.  
  101. " Save/Reload session
  102. set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
  103. nmap <silent> <leader>ss <Esc>:mksession! $VIM/.session<CR>
  104. nmap <silent> <leader>ls <Esc>:source $VIM/.session<CR>
  105.  
  106. " Convenient command to see the difference between the current buffer and the
  107. " file it was loaded from, thus the changes you made.
  108. command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
  109. \ | wincmd p | diffthis
  110.  
  111. " NERDTree settings (launch with \nt or \\)
  112. let g:NERDTreeQuitOnOpen = 1
  113. nmap <silent> <leader>nt <Esc>:NERDTreeToggle<CR>
  114. nmap <silent> <leader>\ <Esc>:NERDTreeToggle<CR>
  115.  
  116. " bufexplorer settings (launch with \be or \])
  117. nmap <silent> <unique> <leader>] <Esc>:BufExplorer<CR>
  118.  
  119. " Tab navigation
  120. nmap <silent> <C-t> :tabnew<CR>
  121. nmap <silent> <C-j> gT
  122. nmap <silent> <C-k> gt
  123. nmap <silent> <C-h> :tabfirst<CR>
  124. nmap <silent> <C-l> :tablast<CR>
  125. nmap <silent> <leader>ta <Esc>:tab ball<CR>
  126.  
  127. " Split window navigation
  128. nmap <c-down> <c-w>w
  129. nmap <c-up> <c-w>W
  130. nmap <c-left> <c-w>h
  131. nmap <c-right> <c-w>l
  132.  
  133. " Undo in Insert mode (CTRL+Z)
  134. map <c-z> <c-o>u
  135.  
  136. " Remap omni-completion to CTRL+SPACE
  137. inoremap <C-space> <C-x><C-o>
  138.  
  139. " Most recently used file list settings
  140. let MRU_Max_Entries = 50
  141.  
  142. " Use SQL Server syntax file for .sql files
  143. let g:sql_type_default = "sqlserver"
  144.  
  145. " Functions for cleaning up tabs and spaces
  146. function! RemoveTrailingSpaces()
  147. %s/\s\+$//e
  148. %s/
  149. //ge
  150. endfunction
  151.  
  152. function! ConvertTabsToSpaces()
  153. %retab
  154. endfunction
  155.  
  156. function! CleanFile()
  157. call ConvertTabsToSpaces()
  158. call RemoveTrailingSpaces()
  159. endfunction
  160.  
  161. " Key binding \f to clean up file
  162. nmap <silent> <leader>f <Esc>:call CleanFile()<CR>
  163.  
  164. " Format of GUI tab label
  165. function! GuiTabLabel()
  166. " add the tab number
  167. let label = '['.tabpagenr()
  168.  
  169. " modified since the last save?
  170. let buflist = tabpagebuflist(v:lnum)
  171. for bufnr in buflist
  172. if getbufvar(bufnr, '&modified')
  173. let label .= '*'
  174. break
  175. endif
  176. endfor
  177.  
  178. " count number of open windows in the tab
  179. let wincount = tabpagewinnr(v:lnum, '$')
  180. if wincount > 1
  181. let label .= ', '.wincount
  182. endif
  183. let label .= '] '
  184.  
  185. " add the file name without path information
  186. let n = bufname(buflist[tabpagewinnr(v:lnum) - 1])
  187. let label .= fnamemodify(n, ':t')
  188.  
  189. return label
  190. endfunction
  191. set guitablabel=%{GuiTabLabel()}
  192.  
  193. " C-specific settings
  194. set makeprg=gcc\ -o\ %<\ %
  195. :command -nargs=* Make make <args> | cwindow 3
  196.  
  197. " Python-specific settings
  198. autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
  199. autocmd BufWritePre *.py normal m`:%s/\s\+$//e ``
  200. autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
  201. autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
  202. autocmd FileType python set omnifunc=pythoncomplete#Complete
  203.  
  204. " Special functions for debugging/launching Python scripts
  205. " http://www.petersblog.org/node/752
  206. python << EOF
  207. import vim
  208. import string
  209.  
  210. def SetBreakpoint():
  211. import re
  212.  
  213. nLine = int(vim.eval('line(".")'))
  214.  
  215. strLine = vim.current.line
  216. strWhite = re.search('^(\s*)', strLine).group(1)
  217.  
  218. vim.current.buffer.append(
  219. "%(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s" %
  220. {'space':strWhite, 'mark': '#' * 30}, nLine - 1)
  221.  
  222. for strLine in vim.current.buffer:
  223. if strLine == "import pdb":
  224. break
  225. else:
  226. vim.current.buffer.append('import pdb', 0)
  227. vim.command('normal j1')
  228.  
  229. vim.command('map <f7> :py SetBreakpoint()<cr>')
  230.  
  231. def RemoveBreakpoints():
  232. import re
  233.  
  234. nCurrentLine = int(vim.eval('line(".")'))
  235.  
  236. nLines = []
  237. nLine = 1
  238. for strLine in vim.current.buffer:
  239. if strLine == 'import pdb' or strLine.lstrip()[:15] == 'pdb.set_trace()':
  240. nLines.append(nLine)
  241. nLine += 1
  242.  
  243. nLines.reverse()
  244.  
  245. for nLine in nLines:
  246. vim.command('normal %dG' % nLine)
  247. vim.command('normal dd')
  248. if nLine < nCurrentLine:
  249. nCurrentLine -= 1
  250.  
  251. vim.command('normal %dG' % nCurrentLine)
  252.  
  253. vim.command('map <s-f7> :py RemoveBreakpoints()<cr>')
  254.  
  255. def RunDebugger():
  256. vim.command('wall')
  257. strFile = vim.eval("g:mainfile")
  258. winos = vim.eval('has("win32")')
  259. if string.atoi(winos):
  260. vim.command("!start python -m pdb %s" % strFile)
  261. else:
  262. vim.command("!xterm -e python -m pdb %s&" % strFile)
  263.  
  264. def RunNormal():
  265. vim.command('wall')
  266. strFile = vim.eval('expand("%:p")')
  267. winos = vim.eval('has("win32")')
  268. if string.atoi(winos):
  269. vim.command("!start python %s" % strFile)
  270. else:
  271. vim.command("!xterm -e python %s&" % strFile)
  272.  
  273. def RunNormalInDebugMode():
  274. vim.command('wall')
  275. strFile = vim.eval('expand("%:p")')
  276. winos = vim.eval('has("win32")')
  277. if string.atoi(winos):
  278. vim.command("!start python %s --debug-mode" % strFile)
  279. else:
  280. vim.command("!xterm -e python %s --debug-mode&" % strFile)
  281.  
  282. vim.command('map <s-f12> :py RunDebugger()<cr>')
  283. vim.command('map <f5> :py RunNormal()<cr>')
  284. vim.command('map <s-f5> :py RunNormalInDebugMode()<cr>')
  285. EOF

Report this snippet  

You need to login to post a comment.