Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 247 lines (202 sloc) 7.738 kb
63af46f @scrooloose add the useful parts of my vimrc
authored
1 "Use Vim settings, rather then Vi settings (much better!).
2 "This must be first, because it changes other options as a side effect.
3 set nocompatible
4
5 "allow backspacing over everything in insert mode
6 set backspace=indent,eol,start
7
8 "store lots of :cmdline history
9 set history=1000
10
11 set showcmd "show incomplete cmds down the bottom
12 set showmode "show current mode down the bottom
13
14 set incsearch "find the next match as we type the search
15 set hlsearch "hilight searches by default
16
17 set nowrap "dont wrap lines
18 set linebreak "wrap lines at convenient points
19
03cf502 @scrooloose make the statusline own harder
authored
20 "Add the variable with the name a:varName to the statusline. Highlight it as
21 "'error' unless its value is in a:goodValues (a comma separated string)
22 function! AddStatuslineFlag(varName, goodValues)
23 set statusline+=%#error#
24 exec "set statusline+=%{RenderStlFlag(".a:varName.",'".a:goodValues."',1)}"
25 set statusline+=%*
26 exec "set statusline+=%{RenderStlFlag(".a:varName.",'".a:goodValues."',0)}"
27 endfunction
28
29 "returns a:value or ''
30 "
31 "a:goodValues is a comma separated string of values that shouldn't be
32 "highlighted with the error group
33 "
34 "a:error indicates whether the string that is returned will be highlighted as
35 "'error'
36 "
37 function! RenderStlFlag(value, goodValues, error)
535d37c @scrooloose make the statusline own harder
authored
38 let goodValues = split(a:goodValues, ',', 1)
03cf502 @scrooloose make the statusline own harder
authored
39 let good = index(goodValues, a:value) != -1
40 if (a:error && !good) || (!a:error && good)
535d37c @scrooloose make the statusline own harder
authored
41 return '[' . a:value . ']'
03cf502 @scrooloose make the statusline own harder
authored
42 else
43 return ''
44 endif
45 endfunction
46
63af46f @scrooloose add the useful parts of my vimrc
authored
47 "statusline setup
48 set statusline=%t "tail of the filename
535d37c @scrooloose make the statusline own harder
authored
49 call AddStatuslineFlag('&ff', 'unix,') "fileformat
50 call AddStatuslineFlag('&fenc', 'utf-8,') "file encoding
63af46f @scrooloose add the useful parts of my vimrc
authored
51 set statusline+=%h "help file flag
52 set statusline+=%y "filetype
26a6792 @scrooloose make the statusline own harder
authored
53 set statusline+=%r "read only flag
54 set statusline+=%m "modified flag
03cf502 @scrooloose make the statusline own harder
authored
55
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
56 "display a warning if &et is wrong, or we have mixed-indenting
03cf502 @scrooloose make the statusline own harder
authored
57 set statusline+=%#error#
58 set statusline+=%{StatuslineTabWarning()}
59 set statusline+=%*
60
26a6792 @scrooloose make the statusline own harder
authored
61 set statusline+=%{StatuslineTrailingSpaceWarning()}
63af46f @scrooloose add the useful parts of my vimrc
authored
62 set statusline+=%= "left/right separator
26a6792 @scrooloose make the statusline own harder
authored
63 set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight
63af46f @scrooloose add the useful parts of my vimrc
authored
64 set statusline+=%c, "cursor column
65 set statusline+=%l/%L "cursor line/total lines
66 set statusline+=\ %P "percent through file
67 set laststatus=2
68
26a6792 @scrooloose make the statusline own harder
authored
69 "recalculate the trailing whitespace warning when idle, and after saving
70 autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
71
72 "return '[\s]' if trailing white space is detected
73 "return '' otherwise
74 function! StatuslineTrailingSpaceWarning()
75 if !exists("b:statusline_trailing_space_warning")
76 if search('\s\+$', 'nw') != 0
77 let b:statusline_trailing_space_warning = '[\s]'
78 else
79 let b:statusline_trailing_space_warning = ''
80 endif
81 endif
82 return b:statusline_trailing_space_warning
83 endfunction
84
85
86 "return the syntax highlight group under the cursor ''
ce89cd0 @scrooloose add hilight group under cursor to statusline
authored
87 function! StatuslineCurrentHighlight()
88 let name = synIDattr(synID(line('.'),col('.'),1),'name')
26a6792 @scrooloose make the statusline own harder
authored
89 if name == ''
90 return ''
91 else
92 return '[' . name . ']'
ce89cd0 @scrooloose add hilight group under cursor to statusline
authored
93 endif
94 endfunction
95
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
96 "recalculate the tab warning flag when idle and after writing
97 autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
98
99 "return '[&et]' if &et is set wrong
100 "return '[mixed-indenting]' if spaces and tabs are used to indent
101 "return an empty string if everything is fine
03cf502 @scrooloose make the statusline own harder
authored
102 function! StatuslineTabWarning()
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
103 if !exists("b:statusline_tab_warning")
104 let tabs = search('^\t\+[^ \t]*', 'nw') != 0
105 let spaces = search('^ \+[^ \t]*', 'nw') != 0
106
107 if tabs && spaces
108 let b:statusline_tab_warning = '[mixed-indenting]'
109 elseif (spaces && !&et) || (tabs && &et)
110 let b:statusline_tab_warning = '[&et]'
111 else
112 let b:statusline_tab_warning = ''
113 endif
03cf502 @scrooloose make the statusline own harder
authored
114 endif
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
115 return b:statusline_tab_warning
03cf502 @scrooloose make the statusline own harder
authored
116 endfunction
117
63af46f @scrooloose add the useful parts of my vimrc
authored
118 "indent settings
119 set shiftwidth=4
120 set softtabstop=4
121 set expandtab
122 set autoindent
123
124 "folding settings
125 set foldmethod=indent "fold based on indent
126 set foldnestmax=3 "deepest fold is 3 levels
127 set nofoldenable "dont fold by default
128
129 set wildmode=list:longest "make cmdline tab completion similar to bash
130 set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
131
132 "display tabs and trailing spaces
133 set list
134 set listchars=tab:▷⋅,trail:⋅,nbsp:⋅
135
136 set formatoptions-=o "dont continue comments when pushing o/O
137
138 "vertical/horizontal scroll off settings
139 set scrolloff=3
140 set sidescrolloff=7
141 set sidescroll=1
142
143 "load ftplugins and indent files
144 filetype plugin on
145 filetype indent on
146
147 "turn on syntax highlighting
148 syntax on
149
150 "some stuff to get the mouse going in term
151 set mouse=a
152 set ttymouse=xterm2
153
154 "tell the term has 256 colors
155 set t_Co=256
156
157 "hide buffers when not displayed
158 set hidden
159
332c677 @scrooloose dont source csapprox if we dont have gui support
authored
160 "dont load csapprox if we no gui support - silences an annoying warning
161 if !has("gui")
162 let g:CSApprox_loaded = 1
163 endif
164
63af46f @scrooloose add the useful parts of my vimrc
authored
165 "make <c-l> clear the highlight as well as redraw
166 nnoremap <C-L> :nohls<CR><C-L>
167 inoremap <C-L> <C-O>:nohls<CR>
168
6c1c2ae @scrooloose add map to buf explorer
authored
169 "map to bufexplorer
170 nnoremap <C-B> :BufExplorer<cr>
171
28dcbf3 @scrooloose add fuzzyfinder textmate style mod
authored
172 "map to fuzzy finder text mate stylez
173 nnoremap <c-f> :FuzzyFinderTextMate<CR>
174
63af46f @scrooloose add the useful parts of my vimrc
authored
175 "map Q to something useful
176 noremap Q gq
177
178 "make Y consistent with C and D
179 nnoremap Y y$
180
181 "visual search mappings
182 function! s:VSetSearch()
183 let temp = @@
184 norm! gvy
185 let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
186 let @@ = temp
187 endfunction
188 vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR>
189 vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR>
190
191
f170376 @scrooloose add some more to the vimrc
authored
192 "jump to last cursor position when opening a file
193 "dont do it when writing a commit log entry
63af46f @scrooloose add the useful parts of my vimrc
authored
194 autocmd BufReadPost * call SetCursorPosition()
195 function! SetCursorPosition()
196 if &filetype !~ 'commit\c'
197 if line("'\"") > 0 && line("'\"") <= line("$")
198 exe "normal g`\""
199 endif
200 end
201 endfunction
202
f170376 @scrooloose add some more to the vimrc
authored
203 "define :Lorem command to dump in a paragraph of lorem ipsum
204 command! -nargs=0 Lorem :normal iLorem ipsum dolor sit amet, consectetur
205 \ adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
206 \ magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
207 \ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
208 \ irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
209 \ fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
210 \ proident, sunt in culpa qui officia deserunt mollit anim id est
211 \ laborum
212
213 "define :HighlightExcessColumns command to highlight the offending parts of
214 "lines that are "too long". where "too long" is defined by &textwidth or an
03cf502 @scrooloose make the statusline own harder
authored
215 "arg passed to the command
f170376 @scrooloose add some more to the vimrc
authored
216 command! -nargs=? HighlightExcessColumns call s:HighlightExcessColumns('<args>')
217 function! s:HighlightExcessColumns(width)
218 let targetWidth = a:width != '' ? a:width : &textwidth
219 if targetWidth > 0
220 exec 'match Todo /\%>' . (targetWidth+1) . 'v/'
221 else
222 echomsg "HighlightExcessColumns: set a &textwidth, or pass one in"
223 endif
224 endfunction
63af46f @scrooloose add the useful parts of my vimrc
authored
225
226 "simple template system
227 command! -complete=customlist,<SID>AvailableTemplates -n=1
228 \ Template :call <SID>InsertTemplate('<args>')
229
230 function! <SID>InsertTemplate(name)
231 "read in the template
232 execute 'read ~/.vim/templates/' . &filetype . '/' . a:name
233
234 "if the cursor was previously on a blank line, delete it
235 if getline(line(".")-1) =~ '^\s*$'
236 exec line(".")-1 . 'd'
237 endif
238 endfunction
239
240 function! <SID>AvailableTemplates(lead, cmdline, cursorpos)
241 let templateDir = expand('~/.vim/templates/' . &filetype . '/')
242 let files = split(globpath(templateDir, a:lead . '*'), '\n')
243
244 "chop off the templateDir from each file
245 return map(files, 'strpart(v:val,strlen(templateDir))')
246 endfunction
Something went wrong with that request. Please try again.