" Note, this config is many years old and needs serious updating. " }}} " vim:sw=4 ts=4 sts=4 foldmethod=marker " MAPPINGS: {{{1 set encoding=utf-8 "the world is big " " " set tab stops to 4 set sw=4 set ts=4 set sts=4 " mapping that should change: -, +, _ " j and k should go to first non-whitespace. " |i_CTRL-Y| " " " paste unnamed register inoremap " " when pasting, don't yank the pasted over text vnoremap p "_dP " save inoremap :update "swap " and ' noremap " ' noremap ' " " Make ctrl-n and ctrl-p cycle through buffers in cmd mode nnoremap :bn nnoremap :bp " quick command line window. noremap m q:k " mark noremap m noremap , q:i noremap Q , noremap q: Q " yank to end of line map Y y$ " Insert a single char nmap ir " Previously unmammed keys. " yank document to clipboard noremap - mzgg"+yG'zzz " save noremap :w " current_file:line_number nmap \x :let @"=expand("%:t") . ':' . line(".") " split common files noremap :tabe ~/.vimrc noremap :tabe ~/t " paste clipboard noremap "+p noremap "+P " alt-shift-letter has some terminal incompatibilities, so " this needs to find a new key: inoremap + " yank clipboard noremap "+y:let@*=@+ " easier window, tab and quickfix cycling noremap w noremap :cn noremap :cp " needs new key "nohl noremap :nohl inoremap :nohl " make x and X not affect registers noremap x "_x noremap X "_X "stop # from unindenting newlines with smartcase inoremap # X# "make * and # in visual mode search for the selection, instead of word under cursor. vnoremap * :call VSearch()/ vnoremap # :call VSearch()? function! s:VSearch() let old = @" norm! gvy let @/ = '\V' . substitute(escape(@", '\'), '\n', '\\n', 'g') let @" = old endfunction " remove trailing whitespace nnoremap :%s/\s\+$//:unlet! b:statusline_trailing_space_warning " easy vim.. use ctrl-o and ctrl-l to use normal mode. noremap :call easyVim() inoremap :call easyVim() function! s:easyVim() if !&insertmode set insertmode "menu and button stuff. set go+=m set go+=T " right scrollbar set go+=r " left scrollbar set go+=L else set noinsertmode set go-=m set go-=T set go-=r set go-=L endif endfunction " found this to compile the current buffer, took a bit from it "function Make() "let curr_dir = expand('%:h') "if curr_dir == '' "let curr_dir = '.' "endif "echo curr_dir "execute 'lcd ' . curr_dir "execute 'make %:r.o' "execute 'lcd -' "endfun "imap :wa:call Make() "nmap :wa:call Make() " standard make " haven't been using it so its getting kicked out "inoremap :wa:make "nnoremap :wa:make inoremap gT nnoremap gT inoremap gt nnoremap gt " used to have !silent, but if make fails without an error that vim can parse, " it doesn't show any failure, which is extremely confusing. I'd like " something that would be silent except for a failure. command! -bar -complete=file -nargs=* Make lcd %:h | make | cw nnoremap :wa:Make inoremap :wa:Make nnoremap :!./run.sh nnoremap :silent! !ctags -R .:redr! " Execute the current line. nnoremap "pyy:@p vnoremap :call ExecRegion('vis') function! ExecRegion(type, ...) if a:type == "vis" " Yank and execute the visual region. :'<,'> y p @p endif endfun " EX COMMANDS: {{{1 " originally I was using a macro for this " do yy@0 on the next line " ggzn/^{{ nyyddnkk::r !date +"\%I:\%M \%p \%A \%D" < :call setline(".", strftime("%I:%M %p %A %d/%m/%y")) command! T :call setline(".", strftime("%I:%M %p %A %d/%m/%y")) " need to lookup the cross platform date for this one command! D :r !date +"\%D" " for my super simple version control. command! -nargs=* I w|!ii % command! -nargs=* O w|!io % " ABREVIATIONS: {{{1 ab J) Ïåñ " SETTINGS: {{{1 "taken or modified from gentoo set wildignore+=.info,.aux,.log,.dvi,.bbl,.out,.o,.lo "ignore some files for filename completion " Terminal fixes " todo: make this work like == screen* if &term ==? "xterm" || &term ==? "screen" || &term == "xterm-color" || &term == "screen-bce" set t_Sb=^[4%dm set t_Sf=^[3%dm set ttymouse=xterm2 set term=xterm-color set t_Co=256 "terminal colors endif set virtualedit=block "Allow visual block to move in empty space. set showbreak=\ "show a single character on wrapped lines, uses the non-text highlight. set ttimeoutlen=10 " 10 milliseconds for esc timeout set nocompatible " end of gentoo stuff " Allow split windows to shrink to this size set winminheight=0 " show partial wrapped lines at the bottom set display=lastline " show menu for completion set wildmenu " was auto, but this caused new files created when writting which messes up " my aufs set bkc=yes " we can see what mode we are in from the cursor. set nomodeline " if v:version >= 701 set diffopt=filler,context:1,vertical,foldcolumn:1 endif " grep will sometimes skip displaying the file name if you " search in a singe file. Set grep to always generate a file-name. set grepprg=grep\ -nH\ $* set report=0 " Show a 'N lines were changed' report always set shiftround " < and > will hit indent levels instead of +-4 always " note: for some reason, windows gvim didn't like ~/tmp to be windows " directory link to ../m/tmp. I used a different dir. set backupdir=~/.editor-backups " keep backup files in one directory. set mouse=a " Enable the mouse in all terminals if possible set laststatus=2 set statusline=\|%n\|\ \ %f%M%R%h%W:%l\ \ \|%v»\ %P\|%<\ \ %{getcwd()} set modeline " use modelines when root. security be damned. set listchars=tab:._ "show tabs. set foldignore= " don't ignore # when using foldmethod=indent filetype plugin on filetype indent on set autoindent syntax enable set hlsearch "Tab settings, for reference. "set shiftwidth=2 "set noexpandtab "set softtabstop=2 "set tabstop=2 "End tab settings. set number "viminfo settings " the viminfo file deletes symlinks, so i moved it to tmp/ set vi='100,<1000,s10,h,n~/.viminfo set foldlevel=99 set ic "set ignorecase set scs "set smartcase " allow backspacing over everything in insert mode set backspace=indent,eol,start set backup " keep a backup file set history=1000 " keep 1000 lines of command line history set showcmd " display incomplete commands set incsearch " do incremental searching colorscheme nightsky set foldmethod=indent " Just need to define it. Picked single char 'y' cuz its the smallest let c_no_comment_fold = 1 let c_space_errors = 1 "for folding C preprocessor if, from my syntax addition. "the problem is that sometime " let cpre "for easy x11 cutting and pasting, but it gets in the way. "note: exclude must be the last option. "set clipboard=autoselect,unnamed,exclude:cons\|linux " for syntax highlighting let is_bash = 1 if $OS ==# 'Windows_NT' set directory=p:\tmp,. endif " AUTOCOMMANDS: {{{1 if !exists("autocommands_loaded") let autocommands_loaded = 1 " au BufNewFile,BufRead /usr/src/linux*/** set patchmode=.orig if v:version >= 701 au BufReadPre * set numberwidth=3 endif "au BufEnter * syntax sync fromstart " "my attempt to have foldlevel=0 but still show the cursor. gives errors "when opening help files, so avoid that. au BufWinEnter * if &ft != 'help' | exe "normal zv" | endif " for highlighting c preprocessor conditionals au BufNewFile,BufRead syn match prePConditional "^\s*#\s*\(ifndef\|else\|endif\|ifdef\)" au BufNewFile,BufRead hi link prePConditional WarningMSG " alternate version which highlights only certain things inside the main match "syn match prePSub contained "[^# ]*\>" "syn match prePConditional contains=prePSub "^\s*#\s*\(ifndef\|else\|endif\|ifdef\)" "hi link prePSub DiffText " make shell scripts executable. todo: Make this into an ex command. " au BufWritePost *.sh !/bin/bash -c 'if [ -x % ]; then exit; else /bin/chmod +x %; fi' " When editing a file, always jump to the last cursor position " this is in the reference manual. autocmd BufReadPost * \ if ! exists("g:leave_my_cursor_position_alone") | \ if line("'\"") > 0 && line ("'\"") <= line("$") | \ exe "normal g'\"" | \ endif | \ endif endif autocmd FuncUndefined * exe 'runtime autoload/' . expand('') . '.vim' nnoremap :call SyntaxAttr() " HEX EDITING FUNCTION: {{{1 if has("autocmd") " vim -b : edit binary using xxd-format! augroup Binary au! au BufReadPre *.bin,*.hex setlocal binary au BufReadPost * \ if &binary | exe "Hexmode" | endif au BufWritePre * \ if exists("b:editHex") && b:editHex && &binary | \ exe "%!xxd -r" | \ endif au BufWritePost * \ if exists("b:editHex") && b:editHex && &binary | \ exe "%!xxd" | \ exe "set nomod" | \ endif augroup END endif command Hexmode call ToggleHex() function ToggleHex() " hex mode should be considered a read-only operation " save values for modified and read-only for restoration later, " and clear the read-only flag for now let l:modified=&mod let l:oldreadonly=&readonly let &readonly=0 if !exists("b:editHex") || !b:editHex " save old options let b:oldft=&ft let b:oldbin=&bin " set new options setlocal binary " make sure it overrides any textwidth, etc. let &ft="xxd" " set status let b:editHex=1 " switch to hex editor %!xxd else " restore old options let &ft=b:oldft if !b:oldbin setlocal nobinary endif " set status let b:editHex=0 " return to normal editing %!xxd -r endif " restore values for modified and read only state let &mod=l:modified let &readonly=l:oldreadonly endfunction " Copy matches function {{{1 " Copy matches of the last search to a register (default is the clipboard). " Accepts a range (default is the current line). " Matches are appended to the register and each match is terminated by \n. " Usage: [RANGE]CopyMatches [REGISTER] command! -nargs=0 -range -register CopyMatches call s:CopyMatches(, , "") function! s:CopyMatches(line1, line2, reg) let reg = a:reg != '' ? a:reg : '+' for line in range(a:line1, a:line2) let txt = getline(line) let idx = match(txt, @/) while idx > -1 exec "let @".reg." .= matchstr(txt, @/, idx) . \"\n\"" let end = matchend(txt, @/, idx) let idx = match(txt, @/, end) endwhile endfor endfunction " Miscelany {{{1 " trailing whitespace warning set statusline+=\ \ %{StatuslineTrailingSpaceWarning()} "recalculate the trailing whitespace warning when idle, and after saving autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning "return '[\s]' if trailing white space is detected "return '' otherwise function! StatuslineTrailingSpaceWarning() if !exists("b:statusline_trailing_space_warning") if search('\s\+$', 'nw') != 0 let b:statusline_trailing_space_warning = '[\s]' else let b:statusline_trailing_space_warning = '' endif endif return b:statusline_trailing_space_warning endfunction