X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=vimrc;h=d4f3939d40c4de40d8f993c4f44bb6e031ac3417;hb=17a0e787a304a67188cd10855ae5b2089a7387ec;hp=12ff138f80cb239ab9bd487fbd5b7e24c3b7dd08;hpb=49f77fa2e04f15e20800f18e4f91296aa99d2153;p=config%2Fdotfiles.git diff --git a/vimrc b/vimrc index 12ff138..d4f3939 100644 --- a/vimrc +++ b/vimrc @@ -69,8 +69,8 @@ set history=1000 " Increase number of possible undos. set undolevels=1000 +" Remember marks (including the last cursor position) for more files. if has('viminfo') - " Remember marks (including the last cursor position) for more files. set viminfo^='1000 endif @@ -156,8 +156,8 @@ set incsearch " Activate syntax folding. if has('folding') set foldmethod=syntax - " Only use fold column if we have enough space (for example in a (virtual) - " terminals). + " Only use fold column if we have enough space (for example not in a + " (virtual) terminal which has only 80 columns). if &columns > 80 set foldcolumn=2 endif @@ -270,12 +270,79 @@ if has('statusline') endif endfunction + " Like %f but use relative filename if it's shorter than the absolute path + " (e.g. '../../file' vs. '~/long/path/to/file'). fnamemodify()'s ':.' is + " not enough because it doesn't create '../'s. + function! StatuslineRelativeFilename() + " Display only filename for help files. + if &buftype == 'help' + return expand('%:t') + endif + " Special case for scratch files. + if &buftype == 'nofile' + return '[Scratch]' + endif + + let l:path = expand('%') + " No file. + if l:path == '' + return '[No Name]' + endif + " Path is already relative, nothing to do. + if stridx(l:path, '/') != 0 + return l:path + endif + + " Absolute path to this file. + let l:path = expand('%:p') + " Shortened path to this file, thanks to bairui in #vim on Freenode + " (2012-06-23 00:54) for the tip to use fnamemodify(). This is what + " Vim normally uses as %f (minus some exceptions). + let l:original_path = fnamemodify(l:path, ':~') + " Absolute path to the current working directory. + let l:cwd = getcwd() + + " Working directory completely contained in path, replace it with a + " relative path. Happens for example when opening a file with netrw. + " %f displays this as absolute path, but we want a relative path of + " course. + if stridx(l:path, l:cwd) == 0 + return strpart(l:path, strlen(l:cwd) + 1) + endif + + let l:path_list = split(l:path, '/') + let l:cwd_list = split(l:cwd, '/') + + " Remove the common path. + while l:path_list[0] == l:cwd_list[0] + call remove(l:path_list, 0) + call remove(l:cwd_list, 0) + endwhile + + " Add as many '..' as necessary for the relative path and join the + " path. Thanks to Raimondi in #vim on Freenode (2012-06-23 01:13) for + " the hint to use repeat() instead of a loop. + let l:path = repeat('../', len(l:cwd_list)) . join(l:path_list, '/') + + " Use the shorter path, either relative or absolute. + if strlen(l:path) < strlen(l:original_path) + return l:path + else + return l:original_path + endif + endfunction + set statusline= " on the left set statusline+=%02n " buffer number set statusline+=%{StatuslineBufferCount()} " highest buffer number set statusline+=: - set statusline+=%f\ " path to current file in buffer + if has('modify_fname') + set statusline+=%{StatuslineRelativeFilename()} " path to current file + set statusline+=\ " space after path + else + set statusline+=%f\ " path to current file in buffer + endif set statusline+=%h " [help] if buffer is help file set statusline+=%w " [Preview] if buffer is preview buffer set statusline+=%m " [+] if buffer was modified, @@ -299,7 +366,7 @@ endif " modified by a plugin or other settings. Except for which isn't " affected by mappings. -" Easy way to exit insert mode. +" Easy way to exit insert mode. jk is preferred because it's faster. inoremap jj inoremap jk " Also for command mode, thanks to http://github.com/mitechie/pyvim @@ -358,7 +425,8 @@ endif " Write before suspending, thanks to deryni in #vim on Freenode (2011-05-09 " 20:02 CEST). To suspend without saving either unmap this or use :stop. -" Only the current buffer is written. +" Only the current buffer is written, thus switching to another buffer works +" too. nnoremap :update:stop " 2 gives more verbose information, use it by default. Thanks to NCS_One @@ -586,7 +654,8 @@ if has('syntax') \ '| call matchadd("Error", "\\%u" . l:x)' \ '| endfor' -" Reduce visibility of tabs in contrast to normal SpecialKeys. +" Special highlight for tabs to reduce their visibility in contrast to other +" SpecialKey characters (e.g. ^L). if &t_Co == 256 && HasSyntaxGroup('specialKeyTab') call matchadd('specialKeyTab', '\t') endif @@ -728,7 +797,7 @@ if has('autocmd') \ setlocal textwidth=72 " Use the same comment string as for Vim files in Vimperator files. autocmd FileType vimperator setlocal commentstring=\"%s -" Use tex compiler for (La)TeX files. +" Use TeX compiler for (La)TeX files. autocmd FileType tex compiler tex " FTDETECT AUTO COMMANDS