Monday, March 31, 2025

Re: debuggable vimfiles



Den sön 30 mars 2025 21:53Marc Chantreux <mc@unistra.fr> skrev:
hello,

On Sun, Mar 30, 2025 at 10:41:59AM -0400, D. Ben Knoble wrote:
> > Aside: that's why my ~/.vimrc looks like this so I can
> > easily spot the problematic parts:
>
> I also frequently point folks towards [How to debug my
> vimrc](https://vi.stackexchange.com/q/2003/10604) and [How to debug a
> mapping](https://vi.stackexchange.com/q/7722/10604).

thanks for this pointer. so sad those questions arise in stack* as we have a
user mailing list.

I keep meaning to clean up my .vimrc my ~/.vim/after and my ~/.vim/autoload/bpj/, or at least comment them properly. In practice I just add everything at the bottom or near the top, depending on which works most like intended. The exception is my "text cleanup" function, the various commands which use that function and their config tables where I keep making those tables bigger and more numerous![1]

[1]: An uggly hack really: basically the function takes a possibly empty string of letters and a list of lists where each sublist has three items: an "id" letter which is uppercase for on by default and lowercase for off by default, a string with an ex statement — almost always an `%s///gce` of some complexity and a "description". For example

    ['I', '%s/\v⟮(\_.{-})⟯/_\1_/gce', '⟮...⟯ → _..._']
    or
    ['C', '%s/\v⌈(\_.{-})⌉/\L[\1]{.smallcaps}/gce', '⌈...⌉ → lc .smallcaps']
    or
    ['C', '%s/\v^\s*\zs%(local\s+)?_\s*=\s*\ze\[\=*\[/--/ce', 'void long string to comment']

    (Where ⟮⟯ is a pair of Unicode brackets. Don't ask what I need this for when I have Pandoc!)

    Each command passes its optional argument on to the function as the string of letters for turning an item on/off, whereafter the function executes each enabled item. A bit silly but beats typing all those substitutions every time. I try to keep the choice of letters mnemonic, but when all else files the function 'prints out' some or all lines of the table to a temporary buffer in a new window if it gets a non-empty third argument, which it does if the command was called with a bang. That's how I waste my time...


> > vim9script
> > run r/defaults.vim
> > run r/colors.vim
> >
> > run r/sublime.vim
> >         nnoremap <c-p> :SublimeCtrlP<cr>
> > run ftplugin/man.vim
> >         nnoremap <expr> K
> >         \ &kp == "man"   ? ":Man \<cword>\<cr>"
> >         \ : &kp == ":help" ? "K"
> >         \ : ":KP\<cr>"
> > run r/iab.vim
> > run r/ezfold.vim
> > run r/math.vim
> > run r/buffer_navigation.vim
> > run r/setvts.vim
> > run r/parentheses.vim
> > run r/cmd_makeprg.vim
> >         set aw ar
> >         nnoremap <c-s> :make!<cr>
> >         imap     <c-s> <c-o><c-s>
> > run r/mail-to.vim     | noremap <space>t :To<cr>
> > run r/was_fzy.vim
> > run r/dwm.vim
>
> What an interesting structure. Have you considered using
> `~/.vim/plugin` to have these load automatically?

this was the way I started back in the 90's because it was the
idiomatic way. also when packs came around, I had a most of the stuff
in ~/.vim/pack/*/start.

Nowadays, the only things I kepts in ~/.vim/pack/*/start are the
ftplugins and every addition comes as late as possible.

as example

┌─ /home/mc/.vim/after/ftplugin/python.vim ───
│ vim9script
│ set noet
│ packadd indent-object
│ run indent/python.vim
│ packadd lsp
│ call LspAddServer([{
│       name: 'python',
│       filetype: ['python'],
│       path: 'pylsp',
│       args: [],
│       syncInit: true,
│ }])

│ inoremap  <buffer> (fn def :<cr>……<cr>return ……<esc>2k$i
│ inoremap  <buffer> (wh while :<cr>……<esc>k$i
│ inoremap  <buffer> (wi with :<cr>……<esc>k$i
│ inoremap  <buffer> (aw async with :<cr>……<esc>k$i
│ inoremap  <buffer> (if if :<cr>……<esc>k$i
│ inoremap  <buffer> (ie if :<cr>……<cr>else:<cr>……<esc>3k$i
│ inoremap  <buffer> (fo for X in …… :<cr>……<esc>k^fXs
│ inoremap  <buffer> (af async for X in …… :<cr>……<esc>k^fXs


when I start to chase a bug, comment all the ~/.vimrc lines
and decomment it line by line.

in the process, I have

        inoremap <c-s>:w\|!tmux split vim /tmp/test<cr>

so I can easily see what changed.

regards

--
Marc Chantreux

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/Z-mhAKeSOEEv9NQI%40prometheus.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/CADAJKhBcwFhLU8JEK%2BVUD%3DMfJ8W_VxFbAbqL%2BS5Ez5TY4hRhFA%40mail.gmail.com.

No comments: