vim/parts/main.vim

107 lines
2.8 KiB
VimL
Raw Permalink Normal View History

" 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
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
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//,.
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
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.
2022-08-03 10:51:44 -07:00
" Here's a helpful list of chars:
" ␠ ⎵ ⏎ ·
set list
set listchars=tab:\ \ \|,trail,nbsp:⎵
2022-08-03 10:51:44 -07:00
" jh to escape in insert mode, esc is hard to reach.
"inoremap jh <Esc>
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
2022-08-03 10:51:44 -07:00
augroup clearwhitespace_gp
autocmd!
autocmd BufWritePre * :call StripTrailingWhitespaces()
augroup END
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>
" Autodetect filetypes and set proper indentation
2022-08-03 10:51:44 -07:00
" Default: 4, with tabs.
2023-11-12 09:57:18 -08:00
setlocal 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
" 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()
autocmd FileType text setlocal list
2023-10-14 08:14:24 -07:00
augroup END