vim

James Amberger 2022-08-26T23:59:47.154659Z

I use vim-sexp and fireplace and I fear I’m not really grokking the structural editing. It seems, for example, that pasting an element into a form takes tons of keystrokes. I can yank the form yafbut when I paste it, whether the elements are on a line or one per line, I end up doing manual formatting of one kind or another. In the inline case the least I would expect is thatpasting leaves spaces around the element analogously to yaw or yas followed by p in some prose. What am I missing?

nate 2022-08-27T00:21:55.612309Z

Do you have some small examples to show what is happening? I do a lot of structural editing. Sometimes, the formatting can get wonky, and I hit =- to reformat the top level form. I think that mapping is provided by vim-sexp.

☝️ 1
James Amberger 2022-08-27T00:31:24.198949Z

Yes, I will provide examples ASAP. Thanks!

James Amberger 2022-08-28T12:54:31.971909Z

ok on further reflection at least part of the problem was using the wrong text object. vim-sexp has ae and ie for elements

James Amberger 2022-08-28T13:51:33.840419Z

Still though…

(here is a [form  with a] final-element)
(another-form 1 2)
If I try yae on final-element followed by j$P I get the expected result: (another-form 1 2 final-element) but if instead I do j^p I get ( final-elementanother-form 1 2) which is not good. Also the af object doesn’t seem to have great behavior. Given the same example if I yaf on the inner vector and then put the cursor on the 1 and press p I get (another-form 1[form with a] 2)

James Amberger 2022-08-28T13:53:00.728869Z

The vim-sexp doc does state that the af text object includes the delimiting brackets and not the whitespace but like… that’s not good, right?

nate 2022-08-28T17:20:59.655019Z

wow, very interesting. I've actually never used the text objects that vim-sexp provides. Reading about them now and trying a few out might inspire me to use them more.

nate 2022-08-28T17:29:29.585929Z

The af not including surrounding whitespace is inconsistent with ae, but I think for good reason. forms can be elements (like the inner vector), but elements can never be forms. The element yanking includes whitespace because you are expected to be putting it into another form. Form yanking could be so that the form will stand alone, so the whitespace isn't included. If, as you asked in your second example, you want to put that form into another as an element, then you'll have to supply the extra whitespace.

nate 2022-08-28T17:31:46.714969Z

In the first case (`( final-elementanother-form 1 2)`), the plugin is following these rules: https://github.com/guns/vim-sexp/blob/master/doc/vim-sexp.txt#L125-L136. Perhaps the beginning whitespace is included in ae because it's assumed that if that element is last it will be last where pasted. I don't know the logic of the whitespace inclusion rules. What I would do in that case is yie most of the time and then paste and add whitespace as needed.

James Amberger 2022-08-28T20:13:02.819289Z

well, as you say a form can be an element, so I can pick up some whitespace by putting the cursor on the bracket, ( perhaps, and then yae

nate 2022-08-28T21:31:54.219039Z

Yes, definitely.

🙂 1
Richard Bowen 2022-08-26T06:05:59.115809Z

For prettifying only when I hit a key combination, what do you recommend?

Martynas Maciulevičius 2022-08-26T06:49:39.811289Z

=ap? (try vap to see what region it does it for)