dotfiles/home/dot_vimrc

170 lines
4.5 KiB
Plaintext
Raw Normal View History

" designed for vim 8+ (and inspired by rwxrob)
" https://github.com/starr-dusT/dotfiles
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" general
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set autowrite " automatically write files on close
" tabs and spaces and stuff
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
" undos
set undodir="~/.vim/undodir"
set undofile
" map leader to Space
let mapleader = " "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ui
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2023-12-18 10:53:07 -08:00
syntax enable
set number
set colorcolumn=79
set updatetime=50
set scrolloff=8
set smartindent
set incsearch " hilight search matches while typing
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" wildmenu
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2023-12-18 10:53:07 -08:00
" ignore compiled files
set wildignore=*.o,*~,*.pyc
if has("win16") || has("win32")
set wildignore+=.git\*,.hg\*,.svn\*
else
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
endif
2023-12-18 10:53:07 -08:00
" enable fuzzy finding in the vim command line
set path=$PWD/**
set nowildmenu
set wildmode=list:full
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" netrw
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2023-12-18 10:53:07 -08:00
let g:netrw_banner = 0 " disable dumb banner
" use l and h for up/down dir
augroup netrw_setup | au!
au FileType netrw nmap <buffer> l <CR>
au FileType netrw nmap <buffer> h -
augroup END
2023-12-18 10:53:07 -08:00
map <leader>e :Ex <cr> " open explorer
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2023-12-18 10:53:07 -08:00
" marks
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2023-12-18 10:53:07 -08:00
" allow only global marks
noremap <silent> <expr> ' "'".toupper(nr2char(getchar()))
noremap <silent> <expr> m "m".toupper(nr2char(getchar()))
sunmap '
sunmap m
nnoremap <silent> ' :call ListSelect("marks", "'")<CR> " list jumps/marks
map <leader>md :delmarks A-Z0-9 <cr> " clear marks
2023-12-18 14:11:19 -08:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" grep
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set grepprg=grep\ -snH\ $* " use system grep
command! -nargs=+ -complete=file_in_path -bar Grep cgetexpr Grep(<f-args>)
command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep(<f-args>)
" open quickfix
augroup quickfix
autocmd!
autocmd QuickFixCmdPost cgetexpr cwindow
autocmd QuickFixCmdPost lgetexpr lwindow
augroup END
" grep into quickfix/location list
2023-12-18 14:25:00 -08:00
map <leader>fq :Grep -r<space>
map <leader>fl :LGrep -r<space>
2023-12-18 14:11:19 -08:00
" next/last location
map <leader>nl :lnext<CR>
map <leader>pl :lprev<CR>
" next/last quickfix
map <leader>nc :lnext<CR>
map <leader>pc :lnext<CR>
2023-12-18 10:53:07 -08:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" misc keys
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" open help with word under cursor
map <leader>oh :execute "help " . expand("<cword>")<CR>
2023-12-18 10:53:07 -08:00
" move between splits with hjkl
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
2023-12-18 01:37:16 -08:00
" find
map <leader>ff :find *
2023-12-18 01:27:03 -08:00
" change directories
map <leader>cc :cd<space>
map <leader>cd :cd ~/.local/share/chezmoi <cr>
" open common files
2023-12-18 01:14:41 -08:00
map <leader>ov :e ~/.local/share/chezmoi/home/dot_vimrc <cr>
" functions keys
map <F1> :set number!<CR> :set relativenumber!<CR>
map <F2> :set list!<CR>
map <F3> :set cursorline!<CR>
map <F4> :set spell!<CR>
" better use of arrow keys, number increment/decrement
nnoremap <up> <C-a>
nnoremap <down> <C-x>
2023-12-18 10:53:07 -08:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" helpers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" display and select from a list of marks and jumps
" https://vi.stackexchange.com/a/42965
"
function! ListSelect(command, jump)
2023-12-18 10:53:07 -08:00
execute a:command
echohl Question
echo "Enter mark (ESC to cancel): "
echohl NONE
let mark = toupper(nr2char(getchar()))
redraw
if mark !=# "\e"
try
execute "normal! g" .. a:jump .. mark
catch
echohl ErrorMsg
echo substitute(v:exception, "^Vim(.*):", "", "")
echohl NONE
endtry
endif
endfunction
2023-12-18 14:11:19 -08:00
" better grep wrapper
" https://gist.github.com/romainl/56f0c28ef953ffc157f36cc495947ab3
"
function! Grep(...)
return system(join([&grepprg] + [expandcmd(join(a:000, ' '))], ' '))
endfunction