" Convenient command to see the difference between the current buffer and the " file it was loaded from, thus the changes you made. " Only define it when not defined already. " Revert with: ":delcommand DiffOrig". if !exists(":DiffOrig") command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis \ | wincmd p | diffthis endif if has("vms") set nobackup " do not keep a backup file, use versions instead else set backup " keep a backup file (restore to previous version) if has('persistent_undo') set undofile " keep an undo file (undo changes after closing) endif endif " Don't clutter directories with swap files. " Save them in /tmp instead. set backupdir=/tmp//,. set directory=/tmp//,. set undodir=/tmp//,. if &t_Co > 2 || has("gui_running") " Switch on highlighting the last used search pattern. set hlsearch endif " Put these in an autocmd group, so that we can delete them easily. "augroup vimrcEx " au! " For all text files set 'textwidth' to 78 characters. " autocmd FileType text setlocal textwidth=78 "augroup END " Enable line numbers in the left margin set number set numberwidth=4 " Enable relative line numbers " set relativenumber " Display invisible characters. " Here's a helpful list of chars: " ␠ ⎵ ⏎ · set list set listchars=tab:\ \ \|,trail:·,nbsp:⎵ " jh to escape in insert mode, esc is hard to reach. "inoremap jh " Clears trailing whitespace while preserving cursor. function StripTrailingWhitespaces() let l = line(".") let c = col(".") %s/\s\+$//e call cursor(l, c) endfun augroup clearwhitespace_gp autocmd! autocmd BufWritePre * :call StripTrailingWhitespaces() augroup END " Toggle invisibles in normal mode nnoremap :set list! " Tab size shortcuts " TODO: VSCode-like tab menu nnoremap :set tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab nnoremap :set tabstop=8 shiftwidth=8 softtabstop=4 noexpandtab " Autodetect filetypes and set proper indentation " Default: 4, with tabs. set tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab augroup tabsize_gp autocmd! autocmd Filetype py setlocal tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab autocmd Filetype lua setlocal tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab augroup END " The matchit plugin makes the % command work better, but it is not backwards " compatible. " The ! means the package won't be loaded right away but when plugins are " loaded during initialization. if has('syntax') && has('eval') packadd! matchit endif nmap ToggleHexHighlight let g:pencil#textwidth = 70 augroup pencil autocmd! autocmd FileType markdown,md call pencil#init({'wrap': 'soft'}) autocmd FileType text call pencil#init() autocmd FileType text setlocal list augroup END