2020-05-30 18:17:31 -07:00
|
|
|
" 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")
|
2022-08-03 10:51:44 -07:00
|
|
|
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
|
|
|
|
\ | wincmd p | diffthis
|
2020-05-30 18:17:31 -07:00
|
|
|
endif
|
|
|
|
|
2022-08-03 10:51:44 -07:00
|
|
|
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
|
2020-05-30 18:17:31 -07:00
|
|
|
endif
|
|
|
|
|
2022-08-03 10:51:44 -07:00
|
|
|
" Don't clutter directories with swap files.
|
|
|
|
" Save them in /tmp instead.
|
|
|
|
set backupdir=/tmp//,.
|
|
|
|
set directory=/tmp//,.
|
|
|
|
set undodir=/tmp//,.
|
2020-05-30 18:17:31 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if &t_Co > 2 || has("gui_running")
|
2022-08-03 10:51:44 -07:00
|
|
|
" Switch on highlighting the last used search pattern.
|
|
|
|
set hlsearch
|
2020-05-30 18:17:31 -07:00
|
|
|
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
|
2023-02-25 09:13:48 -08:00
|
|
|
" set relativenumber
|
2020-05-30 18:17:31 -07:00
|
|
|
|
|
|
|
" Display invisible characters.
|
2022-08-03 10:51:44 -07:00
|
|
|
" Here's a helpful list of chars:
|
|
|
|
" ␠ ⎵ ⏎ ·
|
2020-05-30 18:17:31 -07:00
|
|
|
set list
|
2023-02-25 09:13:48 -08:00
|
|
|
set listchars=tab:\ \ \|,trail:·,nbsp:⎵
|
2020-05-30 18:17:31 -07:00
|
|
|
|
2022-08-03 10:51:44 -07:00
|
|
|
" jh to escape in insert mode, esc is hard to reach.
|
|
|
|
"inoremap jh <Esc>
|
2020-05-30 18:17:31 -07:00
|
|
|
|
2022-08-03 10:51:44 -07:00
|
|
|
" Clears trailing whitespace while preserving cursor.
|
|
|
|
function StripTrailingWhitespaces()
|
|
|
|
let l = line(".")
|
|
|
|
let c = col(".")
|
|
|
|
%s/\s\+$//e
|
|
|
|
call cursor(l, c)
|
|
|
|
endfun
|
2020-05-30 18:17:31 -07:00
|
|
|
|
|
|
|
|
2022-08-03 10:51:44 -07:00
|
|
|
augroup clearwhitespace_gp
|
|
|
|
autocmd!
|
|
|
|
autocmd BufWritePre * :call StripTrailingWhitespaces()
|
|
|
|
augroup END
|
|
|
|
|
2020-05-30 18:17:31 -07:00
|
|
|
|
2022-08-03 10:51:44 -07:00
|
|
|
" Toggle invisibles in normal mode
|
|
|
|
nnoremap <F3> :set list! <CR>
|
|
|
|
|
|
|
|
" Tab size shortcuts
|
|
|
|
" TODO: VSCode-like tab menu
|
2023-10-21 14:56:20 -07:00
|
|
|
nnoremap <C-p> :set tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab<CR>
|
|
|
|
nnoremap <C-o> :set tabstop=8 shiftwidth=8 softtabstop=4 noexpandtab<CR>
|
2020-11-20 18:58:39 -08:00
|
|
|
|
|
|
|
" Autodetect filetypes and set proper indentation
|
2022-08-03 10:51:44 -07:00
|
|
|
" Default: 4, with tabs.
|
2023-10-21 14:56:20 -07:00
|
|
|
set tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab
|
2022-08-03 10:51:44 -07:00
|
|
|
augroup tabsize_gp
|
|
|
|
autocmd!
|
2023-10-21 14:56:20 -07:00
|
|
|
autocmd Filetype py setlocal tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab
|
|
|
|
autocmd Filetype lua setlocal tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab
|
2022-08-03 10:51:44 -07:00
|
|
|
augroup END
|
2020-05-30 18:17:31 -07:00
|
|
|
|
|
|
|
" 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 <F2> <Plug>ToggleHexHighlight
|
|
|
|
|
2021-04-09 14:28:18 -07:00
|
|
|
|
|
|
|
let g:pencil#textwidth = 70
|
|
|
|
augroup pencil
|
|
|
|
autocmd!
|
2023-10-21 14:56:20 -07:00
|
|
|
autocmd FileType markdown,md call pencil#init({'wrap': 'soft'})
|
2021-04-09 14:28:18 -07:00
|
|
|
autocmd FileType text call pencil#init()
|
2022-05-06 12:38:33 -07:00
|
|
|
autocmd FileType text setlocal list
|
2023-10-14 08:14:24 -07:00
|
|
|
augroup END
|