Files
dotcommon/vimrc

305 lines
6.6 KiB
VimL

vim9script
source $VIMRUNTIME/defaults.vim
set scrolloff=0
set hlsearch
set directory=~/.vim/swapfiles
set undofile
set undodir=~/.vim/undofiles
set ignorecase smartcase
set smartindent
set autoindent
set shiftwidth=4
set tabstop=4
set expandtab smarttab
set nowrap
set relativenumber number
set viminfofile=~/.vim/viminfo
set omnifunc=syntaxcomplete#Complete
set nrformats+=unsigned
set diffopt+=indent-heuristic
set diffopt+=algorithm:histogram
# Not working in ubuntu
# set diffopt+=linematch:40
# Avoids delay in loading signcolumn/foldcolumn later
set signcolumn=yes
set foldcolumn=1
autocmd Filetype man setlocal signcolumn=no
set ttymouse=sgr
set termguicolors
#" colorscheme stuff{{{
# https://vim.fandom.com/wiki/256_colors_in_vim
# set t_Co=256
# https://github.com/crusoexia/vim-monokai
if 0
silent! colorscheme monokai
else
set background=dark
g:everforest_background = 'hard'
g:everforest_better_performance = 1
colorscheme everforest
endif
#" }}}
set wildmode=longest,list,full # https://stackoverflow.com/q/526858
if exists("&smoothscroll")
set smoothscroll
endif
set splitkeep=screen
packadd! cfilter
packadd! matchit
#" isfname {{{
# https://vim.fandom.com/wiki/Open_file_under_cursor
# Removes '=' from filename chars. This allows paths to be opened with 'gf'
# when assigned to a shell variable. E.g. FOO=/tmp/foo
set isfname-==
#" }}}
set laststatus=2 # always show status bar
set virtualedit=block
set updatetime=100 # For gitgutter to refresh quickly
set autowrite
set autoread
g:gitgutter_preview_win_floating = 1
g:link_heading = ""
set splitbelow splitright
g:mapleader = ' '
autocmd Filetype gitcommit setlocal spell
# Use mouse in normal mode only
set mouse=n
nnoremap <Leader>n :cnext<CR>
nnoremap <Leader>m :cprevious<CR>
g:fzf_command_prefix = 'Fz'
nnoremap <Leader>f :FzFiles<CR>
nnoremap <Leader>g :FzGFiles<CR>
nnoremap <Leader>b :FzBuffers<CR>
command -nargs=1 -complete=dir Tp :tabedit | :tcd <args> | :FzFiles
set modeline # Debian default is off
set history=1000
# The following to save the file as root {{{
# :w !sudo tee %
cnoremap w!! w !sudo tee % > /dev/null
# }}}
set dictionary=/usr/share/dict/words
# Remove "You discovered the command-line window" message {{{
# $VIMRUNTIME/defaults.vim:123
autocmd! vimHints
# }}}
# https://stackoverflow.com/a/6728687
# "vert copen" no longer works, use Ctrl W L to move to vertical split
autocmd filetype qf wincmd J
# TODO: Figure out how to check if that plugin is active
# vim-markdown plugin conceals clutter in markdown and folds sections
autocmd filetype markdown setlocal spell conceallevel=2
autocmd filetype markdown norm zR
autocmd filetype sh,bash setlocal autoindent noexpandtab tabstop=2 shiftwidth=4
autocmd filetype html setlocal shiftwidth=2 tabstop=2
g:lightline = {
active: {
left: [ [ 'mode', 'paste' ], [ 'readonly', 'relativepath', 'modified' ] ],
},
inactive: {
left: [ [ 'readonly', 'relativepath', 'modified' ] ],
}
}
command -bang -range=% -nargs=* Sortc :<line1>,<line2>sort<bang> <args> /\%.v/
command GitBlameLine {
printf("git blame -L %s,%s %s", line('.'), line('.'), expand('%'))
->system()
->substitute("^\^", "", "")
->printf("git log --stat -1 %.8s")
->systemlist()
->popup_atcursor({ "padding": [0, 1, 1, 1] })
->winbufnr()->((bnr) => setbufvar(bnr, '&filetype', 'git'))()
}
nnoremap <silent><leader>hb :GitBlameLine<CR>
def ToggleMouse()
if &mouse == "n"
set mouse=
popup_notification("Mouse OFF", {})
else
set mouse=n
popup_notification("Mouse ON", {})
endif
enddef
nnoremap <silent><leader>om :call <SID>ToggleMouse()<CR>
vnoremap G 10000j
def AllClear()
cclose
lclose
pclose
helpclose
popup_clear()
silent! bd goterm://*
enddef
nnoremap <silent><leader>c :call <SID>AllClear()<CR>
def g:Tapi_TabOpen(bufnum: number, fname: string)
execute "tab drop" fname
enddef
def SendRangeToTerminal(start_line: number, end_line: number, _ = 0)
const terms = term_list()
if terms->empty()
echomsg "No Terminal windows found"
return
endif
var line_num = start_line
for line in getline(start_line, end_line)
line_num += 1
const spl_cmd = line->matchlist('\vVIMST (sleep|ctrl) ([0-9]+|[a-z])?')
if !spl_cmd->empty()
const [_, cmd, arg1; _] = spl_cmd
if cmd == "sleep"
timer_start(arg1->str2nr(), funcref('SendRangeToTerminal', [line_num, end_line]))
return
elseif cmd == "ctrl"
terms[0]->term_sendkeys(nr2char(arg1->char2nr() - 96))
continue
endif
endif
terms[0]->term_sendkeys(line .. "\<CR>")
endfor
enddef
command -range -bar SendToTerm :call <SID>SendRangeToTerminal(<line1>, <line2>)
vnoremap <silent><leader>s :SendToTerm<CR>
nnoremap <silent><leader>s :SendToTerm<CR>
command -range=% -nargs=? -bang Tb {
if "<bang>" == "!"
:<line1>,<line2>s/\v"[^"]*"/\=substitute(submatch(0), " ", "•", "g")/ge
endif
if "<args>" == ""
:<line1>,<line2>!column -t
else
:<line1>,<line2>!column -t -s'<args>'
endif
if "<bang>" == "!"
:<line1>,<line2>s/•/ /ge
endif
}
command -nargs=* -complete=option ModeLine {
if "<args>" == ""
keeppatterns :%s/\%$/\r\r# vim: set filetype=bash foldmethod=marker:/
else
keeppatterns :%s/\%$/\r\r# vim: set <args>:/
endif
}
# Custom text objects
xnoremap <silent> i/ T/ot/
onoremap <silent> i/ :normal vi/<CR>
xnoremap <silent> i, T,ot,
onoremap <silent> i, :normal vi,<CR>
xnoremap <silent> il ^og_
onoremap <silent> il :normal vil<CR>
# Recent vim removed this mapping
#
autocmd Filetype man nnoremap <buffer> <silent> q :q<CR>
command RemoveTrailingSpaces keeppatterns :%s/\v +$//ge
command -range TmuxSend {
for l in getline(<line1>, <line2>)
l->printf("%s \r")
->str2list()
->reduce( (s, c) => printf("%s %x", s, c), "")
->printf("tmux send -Ht .! %s")
->system()
endfor
}
command DateUp keeppatterns s/Last run \zs.*EDT/\=system("date")->trim()/
command -bar LineUp keeppatterns %s/Bala here at \zs[^\"']*\ze[\"']/\=$'{expand("%")}:{line(".")}'/e
# shfmt {{{
def ShFmt()
const win_view = winsaveview()
:%!shfmt
winrestview(win_view)
enddef
augroup ShFmtAG
augroup END
command EnableShFmt {
autocmd! ShFmtAG BufWrite <buffer> call ShFmt()
}
command DisableShFmt {
autocmd! ShFmtAG BufWrite <buffer>
}
# }}}
## nvim defaults
set nojoinspaces
set define=
set sidescroll=1
defcompile
# vim: set fdm=marker: