]> git.r.bdr.sh - rbdr/dotfiles/blame - vim/gvimrc
Add an additional space in the right promptb
[rbdr/dotfiles] / vim / gvimrc
CommitLineData
0d23b6e5
BB
1if has("gui_macvim")
2 " Fullscreen takes up entire screen
3 set fuoptions=maxhorz,maxvert
4
5 " Command-T for CommandT
6 macmenu &File.New\ Tab key=<D-T>
7 map <D-t> :CommandT<CR>
8 imap <D-t> <Esc>:CommandT<CR>
9
10 " Command-Return for fullscreen
11 macmenu Window.Toggle\ Full\ Screen\ Mode key=<D-CR>
12
13 " Command-Shift-F for Ack
14 map <D-F> :Ack<space>
15
16 " Command-e for ConqueTerm
17 map <D-e> :call StartTerm()<CR>
18
19 " Command-/ to toggle comments
20 map <D-/> <plug>NERDCommenterToggle<CR>
21 imap <D-/> <Esc><plug>NERDCommenterToggle<CR>i
22
23
24 " Command-][ to increase/decrease indentation
25 vmap <D-]> >gv
26 vmap <D-[> <gv
27
28 " Map Command-# to switch tabs
29 map <D-0> 0gt
30 imap <D-0> <Esc>0gt
31 map <D-1> 1gt
32 imap <D-1> <Esc>1gt
33 map <D-2> 2gt
34 imap <D-2> <Esc>2gt
35 map <D-3> 3gt
36 imap <D-3> <Esc>3gt
37 map <D-4> 4gt
38 imap <D-4> <Esc>4gt
39 map <D-5> 5gt
40 imap <D-5> <Esc>5gt
41 map <D-6> 6gt
42 imap <D-6> <Esc>6gt
43 map <D-7> 7gt
44 imap <D-7> <Esc>7gt
45 map <D-8> 8gt
46 imap <D-8> <Esc>8gt
47 map <D-9> 9gt
48 imap <D-9> <Esc>9gt
49
50 " Command-Option-ArrowKey to switch viewports
51 map <D-M-Up> <C-w>k
52 imap <D-M-Up> <Esc> <C-w>k
53 map <D-M-Down> <C-w>j
54 imap <D-M-Down> <Esc> <C-w>j
55 map <D-M-Right> <C-w>l
56 imap <D-M-Right> <Esc> <C-w>l
57 map <D-M-Left> <C-w>h
58 imap <D-M-Left> <C-w>h
59
60 " Adjust viewports to the same size
61 map <Leader>= <C-w>=
62 imap <Leader>= <Esc> <C-w>=
63endif
64
65" Don't beep
66set visualbell
67
68" Start without the toolbar
69set guioptions-=T
70
71" Default gui color scheme
72color ir_black
73
74" ConqueTerm wrapper
75function StartTerm()
76 execute 'ConqueTerm ' . $SHELL . ' --login'
77 setlocal listchars=tab:\ \
78endfunction
79
80" Project Tree
81if exists("loaded_nerd_tree")
82 autocmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
83 autocmd FocusGained * call s:UpdateNERDTree()
84 autocmd WinEnter * call s:CloseIfOnlyNerdTreeLeft()
85endif
86
87" Close all open buffers on entering a window if the only
88" buffer that's left is the NERDTree buffer
89function s:CloseIfOnlyNerdTreeLeft()
90 if exists("t:NERDTreeBufName")
91 if bufwinnr(t:NERDTreeBufName) != -1
92 if winnr("$") == 1
93 q
94 endif
95 endif
96 endif
97endfunction
98
99" If the parameter is a directory, cd into it
100function s:CdIfDirectory(directory)
101 let explicitDirectory = isdirectory(a:directory)
102 let directory = explicitDirectory || empty(a:directory)
103
104 if explicitDirectory
105 exe "cd " . fnameescape(a:directory)
106 endif
107
108 " Allows reading from stdin
109 " ex: git diff | mvim -R -
110 if strlen(a:directory) == 0
111 return
112 endif
113
114 if directory
115 NERDTree
116 wincmd p
117 bd
118 endif
119
120 if explicitDirectory
121 wincmd p
122 endif
123endfunction
124
125" NERDTree utility function
126function s:UpdateNERDTree(...)
127 let stay = 0
128
129 if(exists("a:1"))
130 let stay = a:1
131 end
132
133 if exists("t:NERDTreeBufName")
134 let nr = bufwinnr(t:NERDTreeBufName)
135 if nr != -1
136 exe nr . "wincmd w"
137 exe substitute(mapcheck("R"), "<CR>", "", "")
138 if !stay
139 wincmd p
140 end
141 endif
142 endif
143
144 if exists(":CommandTFlush") == 2
145 CommandTFlush
146 endif
147endfunction
148
149" Utility functions to create file commands
150function s:CommandCabbr(abbreviation, expansion)
151 execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
152endfunction
153
154function s:FileCommand(name, ...)
155 if exists("a:1")
156 let funcname = a:1
157 else
158 let funcname = a:name
159 endif
160
161 execute 'command -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '(<f-args>)'
162endfunction
163
164function s:DefineCommand(name, destination)
165 call s:FileCommand(a:destination)
166 call s:CommandCabbr(a:name, a:destination)
167endfunction
168
169" Public NERDTree-aware versions of builtin functions
170function ChangeDirectory(dir, ...)
171 execute "cd " . fnameescape(a:dir)
172 let stay = exists("a:1") ? a:1 : 1
173
174 NERDTree
175
176 if !stay
177 wincmd p
178 endif
179endfunction
180
181function Touch(file)
182 execute "!touch " . shellescape(a:file, 1)
183 call s:UpdateNERDTree()
184endfunction
185
186function Remove(file)
187 let current_path = expand("%")
188 let removed_path = fnamemodify(a:file, ":p")
189
190 if (current_path == removed_path) && (getbufvar("%", "&modified"))
191 echo "You are trying to remove the file you are editing. Please close the buffer first."
192 else
193 execute "!rm " . shellescape(a:file, 1)
194 endif
195
196 call s:UpdateNERDTree()
197endfunction
198
199function Mkdir(file)
200 execute "!mkdir " . shellescape(a:file, 1)
201 call s:UpdateNERDTree()
202endfunction
203
204function Edit(file)
205 if exists("b:NERDTreeRoot")
206 wincmd p
207 endif
208
209 execute "e " . fnameescape(a:file)
210
211ruby << RUBY
212 destination = File.expand_path(VIM.evaluate(%{system("dirname " . shellescape(a:file, 1))}))
213 pwd = File.expand_path(Dir.pwd)
214 home = pwd == File.expand_path("~")
215
216 if home || Regexp.new("^" + Regexp.escape(pwd)) !~ destination
217 VIM.command(%{call ChangeDirectory(fnamemodify(a:file, ":h"), 0)})
218 end
219RUBY
220endfunction
221
222" Define the NERDTree-aware aliases
223if exists("loaded_nerd_tree")
224 call s:DefineCommand("cd", "ChangeDirectory")
225 call s:DefineCommand("touch", "Touch")
226 call s:DefineCommand("rm", "Remove")
227 call s:DefineCommand("e", "Edit")
228 call s:DefineCommand("mkdir", "Mkdir")
229endif
230
231" Include user's local vim config
232if filereadable(expand("~/.gvimrc.local"))
233 source ~/.gvimrc.local
234endif