Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added mah vimrc

  • Loading branch information...
commit b96a25f6e3853ebdc51e2d1c5f8762655be38312 1 parent 946bc09
Richo Healey authored February 08, 2011

Showing 1 changed file with 240 additions and 0 deletions. Show diff stats Hide diff stats

  1. 240  blog/vimrc/vimrc
240  blog/vimrc/vimrc
... ...
@@ -0,0 +1,240 @@
  1
+" .vimrc
  2
+" $Id: .vimrc 601 2011-02-02 22:26:52Z richo $
  3
+" Rich Healey '10
  4
+" This file depends upon a few other bits and pieces. If you're using it and
  5
+" it's throwing errors, commend out the blocks that are chucken em.
  6
+"
  7
+" You will want the following:
  8
+"  - python_fn.vim
  9
+"  http://www.vim.org/scripts/script.php?script_id=30
  10
+"
  11
+"  - brainfuck.vim - If you're silly enough to use brainfuck :)
  12
+"  http://www.vim.org/scripts/script.php?script_id=716
  13
+"
  14
+"
  15
+" vi compat is nice, but I'm running vim, and like shiny stuffs
  16
+set nocompatible
  17
+
  18
+" Convert all tab chars to 4spaces
  19
+" This is mainly for python, but I oft use it for haxing together mangled PHP
  20
+function ReTab()
  21
+    %s/\t/    /g
  22
+endfunction
  23
+
  24
+" Strangely this doesn't work properly unless declared early
  25
+filetype on
  26
+filetype indent on
  27
+filetype plugin on
  28
+
  29
+set wildmode=longest,list,full
  30
+set wildmenu
  31
+
  32
+" Show what we've changed in this set of edits
  33
+" I stole this from someone, I forget who. Probably freenode/#vim
  34
+" If it's you let me know.
  35
+command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
  36
+	 	\ | wincmd p | diffthis
  37
+
  38
+" Highlight lines longer than 80 chars.
  39
+" I just flick this on if I'm writing docs or emails, generally.
  40
+command LongL call LONGL()
  41
+function LONGL()
  42
+    if !exists("b:long")
  43
+        let b:long="matching"
  44
+        let w:m1=matchadd('Search', '\%<81v.\%>77v', -1)
  45
+        let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
  46
+    else
  47
+        unlet b:long
  48
+        :call matchdelete(w:m1)
  49
+        :call matchdelete(w:m2)
  50
+    endif
  51
+endfunction
  52
+
  53
+" We oft want to write with sudo
  54
+" Actually, I never want to do that but this is a nice place to keep it.
  55
+"
  56
+command W w !sudo tee % > /dev/null
  57
+
  58
+" Set some sensible defaults
  59
+set nohlsearch
  60
+" There is no feature in the world that I hate as much as hlsearch
  61
+set foldmethod=marker
  62
+syntax on
  63
+set ai
  64
+"set nu
  65
+" Python primarily
  66
+set ts=4
  67
+set et
  68
+set sw=4
  69
+" Autoindent is nice, but if it does something you don't expect, not being
  70
+" able to backspace it back to sanity is frustrating, even if <ESC>I is
  71
+" quicker.
  72
+set backspace=indent
  73
+set ffs=unix,dos
  74
+
  75
+" Hax to let us have multiple highlights within a single file
  76
+" http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_file
  77
+" This took me so long to find and get working properly.
  78
+function! TextEnableCodeSnip(filetype,start,end,textSnipHl) abort "{{{
  79
+  let ft=toupper(a:filetype)
  80
+  let group='textGroup'.ft
  81
+  if exists('b:current_syntax')
  82
+    let s:current_syntax=b:current_syntax
  83
+    " Remove current syntax definition, as some syntax files (e.g. cpp.vim)
  84
+    " do nothing if b:current_syntax is defined.
  85
+    unlet b:current_syntax
  86
+  endif
  87
+  execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
  88
+  try
  89
+    execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
  90
+  catch
  91
+  endtry
  92
+  if exists('s:current_syntax')
  93
+    let b:current_syntax=s:current_syntax
  94
+  else
  95
+    unlet b:current_syntax
  96
+  endif
  97
+  execute 'syntax region textSnip'.ft.'
  98
+  \ matchgroup='.a:textSnipHl.'
  99
+  \ start="'.a:start.'" end="'.a:end.'"
  100
+  \ contains=@'.group.'
  101
+  \ containedin=ALL'
  102
+  " XXX ^^ This is needed for PHP, everything in a <?PHP ... ?> block is part
  103
+  " of a highlighting group, which breaks the rule as per vanilla in the wiki.
  104
+endfunction "}}}
  105
+
  106
+" This is probably ready to go now we've left CT
  107
+"{{{ CT Stuffs
  108
+" Hax for editing the vb formula files I used.
  109
+autocmd BufRead *.form set ft=vb
  110
+autocmd BufRead *.vb set ft=vb
  111
+"}}}
  112
+
  113
+"Python Trickery {{{
  114
+" This is a hack for sql files that define plpython functions
  115
+" .plpy is probably a better extension now I think of it...
  116
+" I wrote a lot of functions that lived in a PostgreSQL database in python
  117
+" This was a rule to let the scripts look half decent on screen.
  118
+function CONFIGPYSQL()
  119
+    set ft=sql
  120
+    call TextEnableCodeSnip('python', '#@<py', '#@</py', 'SpecialComment' )
  121
+    command! Mtags call PYTHONTAGS()
  122
+endfunction
  123
+function PYTHONTAGS()
  124
+    silent !ptags
  125
+    redraw!
  126
+endfunction
  127
+autocmd BufRead *.pysql call CONFIGPYSQL()
  128
+autocmd BufRead *.plpy call CONFIGPYSQL()
  129
+"
  130
+function CONFIGPYTHON()
  131
+    call TextEnableCodeSnip('sql', '@begin=sql@', '@end=sql@', 'SpecialComment' )
  132
+    " Fix dodgy python highlighting
  133
+    " I believe this is now fixed.
  134
+    let python_highlight_numbers = 1
  135
+    let python_highlight_builtins = 1
  136
+    let python_highlight_exceptions = 1
  137
+    " Courtesy of
  138
+    " http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/
  139
+    " Execute file being edited with <Shift> + e:
  140
+    map <buffer> <C-e> :w<CR>:!/usr/bin/env python % <CR>
  141
+    " TODO Change this to write out to a temp buffer
  142
+    command! Mtags call PYTHONTAGS()
  143
+endfunction
  144
+au BufRead,BufNewFile *.py{c,w,o,x} set ft=python
  145
+au FileType python call CONFIGPYTHON()
  146
+" This seems to work now
  147
+"autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
  148
+" I used this for a while, I don't any more.
  149
+"}}}
  150
+
  151
+"PHP Trickery {{{
  152
+" Let's face it, PHP contains SQL. End of story
  153
+" This lets my SQL highlight nicely. It would be nice to have a less obtrusive
  154
+" marker though.
  155
+function PHPTAGS()
  156
+    silent !phptags
  157
+    redraw!
  158
+endfunction
  159
+function CONFIGPHP()
  160
+    call TextEnableCodeSnip('sql', '@begin=sql@', '@end=sql@', 'SpecialComment' )
  161
+    command! Mtags call PHPTAGS()
  162
+endfunction
  163
+au FileType php call CONFIGPHP()
  164
+"}}}
  165
+
  166
+" HAML hax {{{
  167
+" Haml likes indents of 2 spaces, just like our ruby.
  168
+au FileType haml call CONFIGRUBY()
  169
+" }}}
  170
+
  171
+" HTML hax {{{
  172
+" Html tends to be heavily indented..
  173
+function CONFIGHTML()
  174
+    set ts=2
  175
+    set sw=2
  176
+    let g:html_syntax_folding=1
  177
+    setlocal foldmethod=syntax
  178
+endfunction
  179
+au FileType {,x}html call CONFIGHTML()
  180
+" }}}
  181
+
  182
+" Brainfuck hax {{{
  183
+" Brainfuck is excellent. Winrar!
  184
+au BufNewFile,BufRead *.bf set filetype=brainfuck
  185
+" }}}
  186
+
  187
+" Ruby Hax {{{
  188
+" Prawn files are includes for a pdf rendering library
  189
+au BufNewFile,BufRead *.prawn set filetype=ruby
  190
+
  191
+" This is specific to rails apps, but I will not bind it to a particular
  192
+" filetype
  193
+function CONFIGRUBY()
  194
+    set ts=2
  195
+    set sw=2
  196
+    command! Mtags call RUBYTAGS()
  197
+endfunction
  198
+function RUBYTAGS()
  199
+    silent !rbtags
  200
+    redraw!
  201
+endfunction
  202
+function RESTARTRAILSAPP()
  203
+    w
  204
+    silent !touch tmp/restart.txt
  205
+    redraw!
  206
+endfunction
  207
+au FileType ruby call CONFIGRUBY()
  208
+au BufNewFile,BufRead *.erb call CONFIGRUBY()
  209
+command Rrails call RESTARTRAILSAPP()
  210
+command RR call RESTARTRAILSAPP()
  211
+
  212
+" }}}
  213
+
  214
+" Makefile Hax {{{
  215
+"
  216
+" In Makefile, automatically convert eight spaces at the beginning
  217
+" of line to tab, as you type (or paste).
  218
+au FileType make :inoremap <buffer><silent><Space> <Space><c-o>:call MapSpaceInMakefile()<CR>
  219
+function! MapSpaceInMakefile()
  220
+  " if this space is 8th space from the beginning of line, replace 8 spaces with
  221
+  " one tab (only at the beginning of file)
  222
+  let line = getline('.')
  223
+  let col = col('.')
  224
+  if strpart(line, 0, 8) == ' '
  225
+    let new = "\t" . strpart(line,8)
  226
+    call setline('.', new )
  227
+  endif
  228
+  return ""
  229
+endfunction
  230
+" }}} 
  231
+
  232
+
  233
+
  234
+" XML Hax {{{
  235
+" http://vim.wikia.com/wiki/Vim_as_XML_Editor
  236
+" I can't fathom why this isn't a default
  237
+let g:xml_syntax_folding=1
  238
+au FileType xml setlocal foldmethod=syntax
  239
+"au FileType xml normal zR
  240
+" }}}

0 notes on commit b96a25f

Please sign in to comment.
Something went wrong with that request. Please try again.