Added visual remap commands to find selection in visual mode.
[profile.git] / .vimrc
1 " $Id$
2 se nocp
3 se ts=2
4 se bs=2
5 se sw=2
6 se expandtab
7 se ruler
8 se cindent
9 se cinkeys=0{,0},0),:,!^F,o,O,e
10 se showcmd
11 se go=agilmrtT
12 se hlsearch
13 se incsearch
14 se ignorecase
15 se smartcase
16 se shm=aot
17 se laststatus=2
18 syn enable
19 if has("gui_running")
20   se guifont=Bitstream\ Vera\ Sans\ Mono\ 12
21   colo darkblue
22 endif
23 highlight StatusLine guifg=white guibg=blue ctermbg=white ctermfg=blue
24 if has("win32")
25   se guifont=Bitstream_Vera_Sans_Mono:h10:cANSI
26 endif
27 :autocmd!
28
29 " Set up our variables.
30 fun! Iain_Vars()
31   if ! exists("b:iainlist") | let b:iainlist = 0 | endif
32   if ! exists("b:iainhex") | let b:iainhex = 1 | endif
33 endfun
34
35 fun! Cycle_List()
36   call Iain_Vars()
37   let b:iainlist = b:iainlist + 1
38   if b:iainlist > 2 | let b:iainlist = 0 | endif
39   if b:iainlist == 0
40     set nolist
41   elseif b:iainlist == 1
42     set lcs=tab:\\_,trail:_,extends:<,precedes:>
43     set list
44   else
45     set lcs=tab:\\_,trail:_,extends:<,precedes:>,eol:$
46     set list
47   endif
48 endfun
49
50 fun! Show_List()
51   call Iain_Vars()
52   if b:iainlist == 0
53     " No list.
54     return " "
55   elseif b:iainlist == 1
56     " Just tabs.
57     return "_"
58   else
59     " Full list.
60     return "\$"
61   endif
62 endfun
63
64 " Cycle between hex and decimal display of toolbar stuff.
65 fun! Cycle_StatusLine()
66   call Iain_Vars()
67   let b:iainhex = ! b:iainhex
68   if b:iainhex
69     set statusline=%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%Y%M%R]\ %=0\x%02B\ (%3.6c,%-4.6l)\ 0\x%04.6O\ \|\ %4.6L\ %P
70   else
71     set statusline=%2n\:\ %<%f\ [%{Show_List()}%{Show_Case()}%{Show_Tabstop()}%Y%M%R]\ %=%b\ (%3.6c,%-4.6l)\ %4.6o\ \|\ %4.6L\ %P
72   endif
73 endfun
74
75 " Save the current window width so if we change it we can restore it
76 " when we quit.
77 let andyoldcols=&columns
78
79 " This expands the terminal to display two 80-column files side-by-side
80 " when vim is opened in diff mode.
81 if &diff | let &columns = 164 | endif
82
83 map <C-"> viwvbi"<ESC>ea"<ESC>
84 map - yyp:s/./-/g<RETURN>:let @/=''<RETURN>:<RETURN>
85 map = yyp:s/./=/g<RETURN>:let @/=''<RETURN>:<RETURN>
86 command! W :w
87 se tags=~/.ctags
88
89 " Make * and # work the way you expect in visual mode.
90 vnoremap * y/\V<C-R>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
91 vnoremap # y?\V<C-R>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
92
93 fun! Invert_Case()
94   let &ic = ! &ic
95 endfun
96
97 fun! Show_Case()
98   if &ic | return "c" | else | return "C" | endif
99 endfun
100
101 fun! Show_Tabstop()
102   return &ts
103 endfun
104
105 " Clear Q as we will use it for commands.
106 map Q <Nop>
107
108 " Swap hex/decimal statusline with Qx
109 map Qx :call Cycle_StatusLine()<CR>:<CR>
110 " Swap case-sensitivity with Qc.
111 map Qc :call Invert_Case()<CR>:<CR>
112 " Cycle list styles with Ql.
113 map Ql :call Cycle_List()<CR>:<CR>
114 " Change to ts=2 with Q2.
115 map Q2 :se ts=2<CR>:<CR>
116 " Change to ts=4 with Q4.
117 map Q4 :se ts=4<CR>:<CR>
118 " Change to ts=8 with Q8.
119 map Q8 :se ts=8<CR>:<CR>
120
121 " Vim 7 has tabs.  Default "next tab" mapping is gt.  Add "previous tab" as gb.
122 map gb :tabPrev<CR>
123
124 call Cycle_StatusLine()
125
126 au VimLeave * if exists("andyoldcols") | let &columns=andyoldcols | endif
127
128 " Autocommands to setup features we only want in certain modes...
129
130 " ... For C/C++ files:
131
132 au BufEnter * if &ft == "c" || &ft == "cpp" | call CMode_map() | endif
133 au BufLeave * if &ft == "c" || &ft == "cpp" | call CMode_unmap() | endif
134
135 " ... For Perl files:
136
137 au BufEnter * if &ft == "perl" | call PerlMode_map() | endif
138 au BufLeave * if &ft == "perl" | call PerlMode_unmap() | endif
139
140 " ... For makefiles:
141
142 au BufEnter * if &ft == "make" | call MakeMode_map() | endif
143 au BufLeave * if &ft == "make" | call MakeMode_unmap() | endif
144
145 " Functions to call when we enter/leave a programming language buffer...
146
147 " ... For C-like languages:
148
149 fun! CMode_map()
150   set cinkeys=0{,0},:,0#,!^F,o,O,e
151   set cinwords=if,else,while,do,for,switch
152 endfun
153
154 fun! CMode_unmap()
155 endfun
156
157 " .. For Perl files:
158
159 fun! PerlMode_map()
160   set cinkeys=0{,0},:,!^F,o,O,e
161   set cinwords=if,else,while,do,for,eval
162 endfun
163
164 fun! PerlMode_unmap()
165   set foldmethod=manual
166 endfun
167
168 " ... For makefiles:
169
170 fun! MakeMode_map()
171   set list
172   set noexpandtab
173 endfun
174
175 fun! MakeMode_unmap()
176   set nolist
177   set expandtab
178 endfun