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 n :cnext nnoremap m :cprevious g:fzf_command_prefix = 'Fz' nnoremap f :FzFiles nnoremap g :FzGFiles nnoremap b :FzBuffers command -nargs=1 -complete=dir Tp :tabedit | :tcd | :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 :,sort /\%.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 hb :GitBlameLine def ToggleMouse() if &mouse == "n" set mouse= popup_notification("Mouse OFF", {}) else set mouse=n popup_notification("Mouse ON", {}) endif enddef nnoremap om :call ToggleMouse() vnoremap G 10000j def AllClear() cclose lclose pclose helpclose popup_clear() silent! bd goterm://* enddef nnoremap c :call AllClear() 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 .. "\") endfor enddef command -range -bar SendToTerm :call SendRangeToTerminal(, ) vnoremap s :SendToTerm nnoremap s :SendToTerm command -range=% -nargs=? -bang Tb { if "" == "!" :,s/\v"[^"]*"/\=substitute(submatch(0), " ", "•", "g")/ge endif if "" == "" :,!column -t else :,!column -t -s'' endif if "" == "!" :,s/•/ /ge endif } command -nargs=* -complete=option ModeLine { if "" == "" keeppatterns :%s/\%$/\r\r# vim: set filetype=bash foldmethod=marker:/ else keeppatterns :%s/\%$/\r\r# vim: set :/ endif } # Custom text objects xnoremap i/ T/ot/ onoremap i/ :normal vi/ xnoremap i, T,ot, onoremap i, :normal vi, xnoremap il ^og_ onoremap il :normal vil # Recent vim removed this mapping # autocmd Filetype man nnoremap q :q command RemoveTrailingSpaces keeppatterns :%s/\v +$//ge command -range TmuxSend { for l in getline(, ) 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 call ShFmt() } command DisableShFmt { autocmd! ShFmtAG BufWrite } # }}} ## nvim defaults set nojoinspaces set define= set sidescroll=1 defcompile # vim: set fdm=marker: