1 " Note, this config is many years old and needs serious updating.
4 " vim:sw=4 ts=4 sts=4 foldmethod=marker
6 set encoding=utf-8 "the world is big
13 " mapping that should change: -, +, _
14 " j and k should go to first non-whitespace.
18 " paste unnamed register
21 " when pasting, don't yank the pasted over text
25 inoremap <C-s> <C-o>:update<CR>
32 " Make ctrl-n and ctrl-p cycle through buffers in cmd mode
33 nnoremap <C-N> :bn<Enter>
34 nnoremap <C-P> :bp<Enter>
35 " quick command line window.
44 " Insert a single char
45 nmap <Space> i<Space><Esc>r
47 " Previously unmammed keys.
49 " yank document to clipboard
50 noremap - mzgg"+yG<C-o>'zzz
53 " current_file:line_number
54 nmap \x :let @"=expand("%:t") . ':' . line(".")<cr>
56 noremap <A-q> :tabe ~/.vimrc<CR>
57 noremap <A-k> :tabe ~/t<CR>
61 " alt-shift-letter has some terminal incompatibilities, so
62 " this needs to find a new key:
66 noremap <A-y> "+y:let@*=@+<CR>
67 " easier window, tab and quickfix cycling
74 noremap <silent> <C-l> :nohl<CR><C-l>
75 inoremap <C-l> <C-O>:nohl<CR>
77 " make x and X not affect registers
80 "stop # from unindenting newlines with smartcase
83 "make * and # in visual mode search for the selection, instead of word under cursor.
84 vnoremap * :<C-u>call <SID>VSearch()<CR>/<CR>
85 vnoremap # :<C-u>call <SID>VSearch()<CR>?<CR>
89 let @/ = '\V' . substitute(escape(@", '\'), '\n', '\\n', 'g')
93 " remove trailing whitespace
94 nnoremap <F3> :%s/\s\+$//<CR>:unlet! b:statusline_trailing_space_warning<CR>
96 " easy vim.. use ctrl-o and ctrl-l to use normal mode.
97 noremap <F4> :call <SID>easyVim()<CR>
98 inoremap <F4> <C-o>:call <SID>easyVim()<CR>
102 "menu and button stuff.
119 " found this to compile the current buffer, took a bit from it
121 "let curr_dir = expand('%:h')
126 "execute 'lcd ' . curr_dir
127 "execute 'make %:r.o'
130 "imap <A-b> <Esc>:wa<CR>:call Make()<CR>
131 "nmap <A-b> :wa<CR>:call Make()<CR>
134 " haven't been using it so its getting kicked out
135 "inoremap <A-d> <Esc>:wa<CR>:make<CR>
136 "nnoremap <A-d> :wa<CR>:make<CR>
137 inoremap <A-d> <Esc>gT
139 inoremap <A-e> <Esc>gt
142 " used to have !silent, but if make fails without an error that vim can parse,
143 " it doesn't show any failure, which is extremely confusing. I'd like
144 " something that would be silent except for a failure.
145 command! -bar -complete=file -nargs=* Make lcd %:h | make <args> | cw
146 nnoremap <A-b> :wa<CR>:Make<CR>
147 inoremap <A-b> <Esc>:wa<CR>:Make<CR>
149 nnoremap <A-c> :!./run.sh<CR>
150 nnoremap <A-t> :silent! !ctags -R .<CR>:redr!<CR>
152 " Execute the current line.
153 nnoremap <A-v> "pyy:@p<CR>
154 vnoremap <A-v> :<C-u>call ExecRegion('vis')<CR>
155 function! ExecRegion(type, ...)
157 " Yank and execute the visual region.
167 " originally I was using a macro for this
168 " do yy@0 on the next line
169 " ggzn/^{{
nyyddnkk::r !date +"\%I:\%M \%p \%A \%D"
<<zm'0pA
170 " now I have hte following command:
171 command! J call JournalEntry()
172 function JournalEntry()
173 normal ggzn/^{{
nyyddnO
\e:call setline(".", strftime("%I:%M %p %A %d/%m/%y"))
<<ddkPzm'0pzvjO
179 " insert date in the format I like
180 noremap <A-s> :call setline(".", strftime("%I:%M %p %A %d/%m/%y"))<CR>
181 command! T :call setline(".", strftime("%I:%M %p %A %d/%m/%y"))<CR>
182 " need to lookup the cross platform date for this one
183 command! D :r !date +"\%D"<CR>
185 " for my super simple version control.
186 command! -nargs=* I w|!ii % <args>
187 command! -nargs=* O w|!io % <args>
197 "taken or modified from gentoo
198 set wildignore+=.info,.aux,.log,.dvi,.bbl,.out,.o,.lo "ignore some files for filename completion
200 " todo: make this work like == screen*
201 if &term ==? "xterm" || &term ==? "screen" || &term == "xterm-color" || &term == "screen-bce"
206 set t_Co=256 "terminal colors
208 set virtualedit=block "Allow visual block to move in empty space.
209 set showbreak=\ "show a single character on wrapped lines, uses the non-text highlight.
212 set ttimeoutlen=10 " 10 milliseconds for esc timeout
214 " end of gentoo stuff
216 " Allow split windows to shrink to this size
219 " show partial wrapped lines at the bottom
222 " show menu for completion
225 " was auto, but this caused new files created when writting which messes up
229 " we can see what mode we are in from the cursor.
234 set diffopt=filler,context:1,vertical,foldcolumn:1
237 " grep will sometimes skip displaying the file name if you
238 " search in a singe file. Set grep to always generate a file-name.
239 set grepprg=grep\ -nH\ $*
240 set report=0 " Show a 'N lines were changed' report always
241 set shiftround " < and > will hit indent levels instead of +-4 always
242 " note: for some reason, windows gvim didn't like ~/tmp to be windows
243 " directory link to ../m/tmp. I used a different dir.
244 set backupdir=~/.editor-backups " keep backup files in one directory.
245 set mouse=a " Enable the mouse in all terminals if possible
247 set statusline=\|%n\|\ \ %f%M%R%h%W:%l\ \ \|%v»\ %P\|%<\ \ %{getcwd()}
248 set modeline " use modelines when root. security be damned.
249 set listchars=tab:._ "show tabs.
250 set foldignore= " don't ignore # when using foldmethod=indent
257 "Tab settings, for reference.
265 " the viminfo file deletes symlinks, so i moved it to tmp/
266 set vi='100,<1000,s10,h,n~/.viminfo
268 set ic "set ignorecase
269 set scs "set smartcase
270 " allow backspacing over everything in insert mode
271 set backspace=indent,eol,start
272 set backup " keep a backup file
273 set history=1000 " keep 1000 lines of command line history
274 set showcmd " display incomplete commands
275 set incsearch " do incremental searching
277 set foldmethod=indent
279 " Just need to define it. Picked single char 'y' cuz its the smallest
280 let c_no_comment_fold = 1
281 let c_space_errors = 1
282 "for folding C preprocessor if, from my syntax addition.
283 "the problem is that sometime
286 "for easy x11 cutting and pasting, but it gets in the way.
287 "note: exclude must be the last option.
288 "set clipboard=autoselect,unnamed,exclude:cons\|linux
291 " for syntax highlighting
296 if $OS ==# 'Windows_NT'
297 set directory=p:\tmp,.
302 if !exists("autocommands_loaded")
303 let autocommands_loaded = 1
307 " au BufNewFile,BufRead /usr/src/linux*/** set patchmode=.orig
309 au BufReadPre * set numberwidth=3
311 "au BufEnter * syntax sync fromstart
313 "my attempt to have foldlevel=0 but still show the cursor. gives errors
314 "when opening help files, so avoid that.
315 au BufWinEnter * if &ft != 'help' | exe "normal zv" | endif
317 " for highlighting c preprocessor conditionals
318 au BufNewFile,BufRead syn match prePConditional "^\s*#\s*\(ifndef\|else\|endif\|ifdef\)"
319 au BufNewFile,BufRead hi link prePConditional WarningMSG
320 " alternate version which highlights only certain things inside the main match
321 "syn match prePSub contained "[^# ]*\>"
322 "syn match prePConditional contains=prePSub "^\s*#\s*\(ifndef\|else\|endif\|ifdef\)"
323 "hi link prePSub DiffText
325 " make shell scripts executable. todo: Make this into an ex command.
326 " au BufWritePost *.sh !/bin/bash -c 'if [ -x % ]; then exit; else /bin/chmod +x %; fi'
328 " When editing a file, always jump to the last cursor position
329 " this is in the reference manual.
330 autocmd BufReadPost *
331 \ if ! exists("g:leave_my_cursor_position_alone") |
332 \ if line("'\"") > 0 && line ("'\"") <= line("$") |
333 \ exe "normal g'\"" |
338 autocmd FuncUndefined * exe 'runtime autoload/' . expand('<afile>') . '.vim'
339 nnoremap <F6> :call SyntaxAttr()<CR>
341 " HEX EDITING FUNCTION: {{{1
344 " vim -b : edit binary using xxd-format!
348 au BufReadPre *.bin,*.hex setlocal binary
350 \ if &binary | exe "Hexmode" | endif
352 \ if exists("b:editHex") && b:editHex && &binary |
356 \ if exists("b:editHex") && b:editHex && &binary |
363 command Hexmode call ToggleHex()
365 " hex mode should be considered a read-only operation
366 " save values for modified and read-only for restoration later,
367 " and clear the read-only flag for now
369 let l:oldreadonly=&readonly
371 if !exists("b:editHex") || !b:editHex
376 setlocal binary " make sure it overrides any textwidth, etc.
380 " switch to hex editor
383 " restore old options
390 " return to normal editing
393 " restore values for modified and read only state
395 let &readonly=l:oldreadonly
398 " Copy matches function {{{1
399 " Copy matches of the last search to a register (default is the clipboard).
400 " Accepts a range (default is the current line).
401 " Matches are appended to the register and each match is terminated by \n.
402 " Usage: [RANGE]CopyMatches [REGISTER]
403 command! -nargs=0 -range -register CopyMatches call s:CopyMatches(<line1>, <line2>, "<reg>")
404 function! s:CopyMatches(line1, line2, reg)
405 let reg = a:reg != '' ? a:reg : '+'
406 for line in range(a:line1, a:line2)
407 let txt = getline(line)
408 let idx = match(txt, @/)
410 exec "let @".reg." .= matchstr(txt, @/, idx) . \"\n\""
411 let end = matchend(txt, @/, idx)
412 let idx = match(txt, @/, end)
419 " trailing whitespace warning
420 set statusline+=\ \ %{StatuslineTrailingSpaceWarning()}
421 "recalculate the trailing whitespace warning when idle, and after saving
422 autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
423 "return '[\s]' if trailing white space is detected
425 function! StatuslineTrailingSpaceWarning()
426 if !exists("b:statusline_trailing_space_warning")
427 if search('\s\+$', 'nw') != 0
428 let b:statusline_trailing_space_warning = '[\s]'
430 let b:statusline_trailing_space_warning = ''
433 return b:statusline_trailing_space_warning