Use exec for efficiency.
[profile.git] / .vimrc
diff --git a/.vimrc b/.vimrc
index 5a3622a..0d66b01 100755 (executable)
--- a/.vimrc
+++ b/.vimrc
@@ -1,4 +1,5 @@
 " $Id$
+se nocp
 se ts=2
 se bs=2
 se sw=2
@@ -8,6 +9,7 @@ se cindent
 se cinkeys=0{,0},0),:,!^F,o,O,e
 se showcmd
 se go=agilmrtT
+se hlsearch
 se incsearch
 se ignorecase
 se smartcase
@@ -24,34 +26,53 @@ if has("win32")
 endif
 :autocmd!
 
-" Initialise list format per buffer.
-au BufEnter * let b:iainlist = 0
+" Set up our variables.
+fun! Iain_Vars()
+  if ! exists("b:iainlist") | let b:iainlist = 0 | endif
+  if ! exists("b:iainhex") | let b:iainhex = 1 | endif
+endfun
 
-fun Cycle_List()
-  let b:iainlist += 1
+fun! Cycle_List()
+  let basic='tab:\\_,trail:_,extends:<,precedes:>'
+  call Iain_Vars()
+  let b:iainlist = b:iainlist + 1
   if b:iainlist > 2 | let b:iainlist = 0 | endif
   if b:iainlist == 0
     set nolist
   elseif b:iainlist == 1
-    set lcs=tab:\\_,trail:_,extends:<,precedes:>
+    exec "set lcs=" . basic
     set list
   else
-    set lcs=tab:\\_,trail:_,extends:<,precedes:>,eol:$
+    exec "set lcs=" . basic . ",eol:$"
     set list
   endif
 endfun
 
-fun Show_List()
+fun! Show_List()
+  call Iain_Vars()
   if b:iainlist == 0
     " No list.
-    return "  "
+    return " "
   elseif b:iainlist == 1
     " Just tabs.
-    return "\\_"
+    return "_"
   else
     " Full list.
-    return "\.\$"
+    return "\$"
+  endif
+endfun
+
+" Cycle between hex and decimal display of toolbar stuff.
+fun! Cycle_StatusLine()
+  call Iain_Vars()
+  let b:iainhex = ! b:iainhex
+  let sl1='%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%{Show_Paste()}%Y%M%R]\ %='
+  let sl2='\ (%3.6c,%-4.6l)\ %4.6o\ \|\ %4.6L\ %P'
+  let hexformat='%b'
+  if b:iainhex
+    let hexformat='0\x%02B'
   endif
+  exec "set statusline=" . sl1 . hexformat . sl2
 endfun
 
 " Save the current window width so if we change it we can restore it
@@ -65,22 +86,53 @@ if &diff | let &columns = 164 | endif
 map <C-"> viwvbi"<ESC>ea"<ESC>
 map - yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>
 map = yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>
-command W :w
+command! W :w
 se tags=~/.ctags
 
-fun Invert_Case()
+" Make * and # work the way you expect in visual mode.
+vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
+vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
+
+fun! Invert_Case()
   let &ic = ! &ic
 endfun
 
-fun Show_Case()
-  if &ic | return "ca" | else | return "Ca" | endif
+fun! Show_Case()
+  if &ic | return "c" | else | return "C" | endif
+endfun
+
+fun! Show_Tabstop()
+  return &ts
+endfun
+
+fun! Show_Paste()
+  if &paste | return "p" | else | return "" | endif
 endfun
 
-set statusline=%2n\:\ %<%t\ [%{Show_List()}][%{Show_Case()}]%y%m%r%=%b\ 0\x%02B\ (%3.6c,%-4.6l)\ %4.6L\ %P
-" Swap case-sensitivity with ,c.
-map ,c :call Invert_Case()<CR>:<CR>
-" Cycle list styles with ,l.
-map ,l :call Cycle_List()<CR>:<CR>
+" Clear Q as we will use it for commands.
+map Q <Nop>
+
+" Swap hex/decimal statusline with Qx
+map Qx :call Cycle_StatusLine()<CR>:<CR>
+" Swap case-sensitivity with Qc.
+map Qc :call Invert_Case()<CR>:<CR>
+" Cycle list styles with Ql.
+map Ql :call Cycle_List()<CR>:<CR>
+" Change to ts=2 with Q2.
+map Q2 :se ts=2<CR>:<CR>
+" Change to ts=4 with Q4.
+map Q4 :se ts=4<CR>:<CR>
+" Change to ts=8 with Q8.
+map Q8 :se ts=8<CR>:<CR>
+" Change to ts=16 with Q6.
+map Q6 :se ts=16<CR>:<CR>
+" Change to ts=32 with Q3.
+map Q3 :se ts=32<CR>:<CR>
+
+" Vim 7 has tabs.  Default "next tab" mapping is gt.  Add "previous tab" as gb.
+map gb :tabPrev<CR>
+
+call Cycle_StatusLine()
 
 au VimLeave * if exists("andyoldcols") | let &columns=andyoldcols | endif
 
@@ -96,11 +148,6 @@ au BufLeave * if &ft == "c" || &ft == "cpp" | call CMode_unmap() | endif
 au BufEnter * if &ft == "perl" | call PerlMode_map() | endif
 au BufLeave * if &ft == "perl" | call PerlMode_unmap() | endif
 
-" ... For PHP files:
-
-au BufEnter * if &ft == "php" | call PHPMode_map() | endif
-au BufLeave * if &ft == "php" | call PHPMode_unmap() | endif
-
 " ... For makefiles:
 
 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
@@ -110,46 +157,33 @@ au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
 
 " ... For C-like languages:
 
-fun CMode_map()
+fun! CMode_map()
   set cinkeys=0{,0},:,0#,!^F,o,O,e
   set cinwords=if,else,while,do,for,switch
 endfun
 
-fun CMode_unmap()
+fun! CMode_unmap()
 endfun
 
 " .. For Perl files:
 
-fun PerlMode_map()
+fun! PerlMode_map()
   set cinkeys=0{,0},:,!^F,o,O,e
   set cinwords=if,else,while,do,for,eval
-  set foldmethod=indent
-endfun
-
-fun PerlMode_unmap()
-  set foldmethod=manual
-endfun
-
-fun PHPMode_map()
-  set nocindent
-  set autoindent
-  set foldmethod=indent
 endfun
 
-fun PHPMode_unmap()
-  set noautoindent
-  set cindent
+fun! PerlMode_unmap()
   set foldmethod=manual
 endfun
 
 " ... For makefiles:
 
-fun MakeMode_map()
+fun! MakeMode_map()
   set list
   set noexpandtab
 endfun
 
-fun MakeMode_unmap()
+fun! MakeMode_unmap()
   set nolist
   set expandtab
 endfun