Fork me on GitHub
#vim
<
2021-05-17
>
Aron00:05:52

Trying to use vim sexp and for 10 minutes continuously every time I did something to the code, something completely surprising happened that I didn't understand even after undoing and retrying. It creates errors in the code and then doesn't let me fix them.

Aron08:05:47

Bunch of demos on what the different motions do, but when the form doesn't fit the screen, and there are errors in the code, it's really hard to see what happens

orestis09:05:01

I'm using the "vim-sexp-mappings-for-regular-people" or whatever the name is, but in the end I've mapped ctrl-<left> and ctrl-<right> in insert mode and use only those. Everything more advanced (even in paredit) confuses me to no end 🙂

grazfather12:05:36

I find most of the sexp libs infuriating for the same reason. I don’t like being surprised by that. For example, if i want to close a parens and accidentally type a square bracket, I can’t delete the square bracket and then type a close paren because deleting the close bracket deletes the opening paren!

grazfather12:05:17

I use emacs mostly for lisp now, and similar to orestis I have disabled most everything except for ‘move sexp within sexp’ and ‘barf/spit’

orestis13:05:22

Thankfully vim allows me to drop out of insert mode and delete whatever I damn please 🙂 Please the generic dab or with vim-surround dsb work nicely with lisps.

Noah Bogart13:05:04

vim-sexp is tough, but sexp-for-regular-people is nice

Noah Bogart13:05:27

>) and <) are very helpful for moving enclosing brackets

Aron18:05:54

can someone who uses vim-sexp with or without the tpope mappings tell me how to have the same effect that parinfer has on indentation? move the block left or right, changing only indentation and moving the parens such that they are balanced? What is weird that everyone talks about structural editing that it's about never getting the code into an incorrect state, but it's actually very easy to achieve that

dominicm20:05:54

>)=ie with tpope <M-S-l>=ie without tpope. Alternatively use >ie instead of =ie dependent on what you're after.

(ns foo)
(:require)
From cursor anywhere in (ns foo)

dominicm20:05:14

I never get the code into a correct state when using vim-sexp.

Aron20:05:12

you mean incorrect I guess?

Aron20:05:53

I have incorrect when I move code around, especially when I move it into some temporary place, or when I copy it from github, same repo, but doing a git checkout --patch is not always the easiest

Aron21:05:33

I need to try these shortcuts, but first read them again from scratch how they are composed. On an unrelated note, it does seem everything got a bit more complicated, like adding a new line in a list was just pressing o at the end of the previous list and the parens were moved automatically, but now I have to >I and <enter>

Aron21:05:06

so five keys instead of one

dominicm15:05:14

Oops, I did mean incorrect yes 😄

dominicm15:05:17

Parinfer is great for certain kinds of operation 🙂 I really like the vim-sexp model as it gives me more re-use & power though. There's just different properties to each of them really.

Aron15:05:25

What I started to realize is just how many steps I have to step back before I can use these mappings, lots of things that I just do automatically relied on the editor formatting my code from incorrect to correct, or giving me an error where it was incorrect. Before cljs I wrote mostly js and I used to just copy paste code and data between files, often commenting out several lines and only after a bunch of these changes to a file started I fixing up the syntax errors.

Aron15:05:42

Now I have to think first about how to format the stuff before I move it into the file. I can see the benefits, but ultimately I like the relaxed paradigm more.

dominicm15:05:06

I don't have these problems because I copy using vim-sexp, which means my copies are perfectly valid syntax too. e.g. yaf is a common operation for me.

Aron15:05:51

Sure, that is the case when the place you copy from is well formatted. I am working on the frontend, and no one else uses clojure around me. So the places I copy from atm. are rarely well formatted S-expressions or opened in vim at all. : )

dominicm20:05:50

I don't really understand your use case, it sounds like you're not copying clojure code.

Aron20:05:43

that's what I said

James Amberger17:11:49

lol. Who’s on first?

Aron12:01:37

hmm? 🙂

Noah Bogart18:05:46

i don't think either handles indentation like that. i usually use the keybinds i mentioned to push the surrouding parenthesis to sexp before or after a given block, and then =iP to reindent the whole paragraph

Aron18:05:37

I see, that would be a nice thing to not lose

dave19:05:01

FWIW, I use parinfer AND vim-sexp with the tpope mappings, and it works well 🙂

dave19:05:15

The 3 plugins are complementary.

Aron03:05:12

what do you do when parinfer ruins your undo?

dave18:05:55

I had that problem a long time ago, but haven't noticed it anytime recently. I think (and have read that) they've fixed it. I'm also in the habit of leaning heavily on git when trying experiments, e.g. I'll make a branch to try out an idea, and if it doesn't work out I just switch back to the branch I was on before. I rarely need to undo more than a few times in a row.

Aron19:05:06

They haven't fixed it for me, this is why I am learning these other mappings. Every couple of hours at least I had to turn parinfer off, do the undo/redo i wanted, then turn it back on. Otherwise it just kept repeating a no-op.

Sigve10:05:13

I also encounter the undo-bug often. Which is keeping me from using parinfer at the moment

Aron10:05:28

same, I would use it happily, but I suspect something I do is very unexpected, or maybe some conflict with another plugin

noisesmith20:05:37

btw =- will reindent the entire top level form, saves some clicks / shift key chording

Aron03:05:39

what do you do when pressing -= messes up indentation?

noisesmith12:05:58

I've never gotten the order wrong, strangely

noisesmith12:05:51

wait - do you mean that you don't like the rules auto-indent uses?

noisesmith12:05:07

my solution is to just use code layouts that auto indent agrees with (all -= does is move one line up, then wait for a movement command for indentation scope, so I misunderstood you at first) anyway, this was a reply to the comment above about using =iP which does the same thing with more awkward keypresses

noisesmith12:05:19

should have put it in that thread actually

noisesmith12:05:27

I have a hard grudge against parinfer after a work scenario where one coworker would check in badly indented code, and another would let intellij move all the parens to match the bad indentation and check that in

noisesmith12:05:21

anyway, it sounds like you don't want text objects for sexps etc. and you just want parinfer, I'm surprised if nobody ever made parinfer for vim

Aron17:05:04

> wait - do you mean that you don't like the rules auto-indent uses? definitely not that, no, what I mean is that no one would like the result, lines get indented incorrectly, this never happens to you? My setup must be faulty then.

noisesmith14:05:28

as long as I indent the whole form, I've never had an issue (though my preferences might be different from others and I'm sure there's corner cases I avoid by restricting where I put line breaks)

Aron14:05:43

I think I found the culprit, and it was my setup, I had another extension enabled that auto-changed shiftwidth, because I used to edit js files, and for some reason in certain cljs files it set it to 10... so when I was indenting, it ended up all weird and unreasonable. Sorry for faulting sexp for this, clearly it had nothing to do with it.

Aron14:05:36

I removed the plugin and now I started using == because easy to remember, I have no idea how indentation works yet, but it makes the code follow the current parens, so I can change the parens then run == again and it kinda works.

noisesmith15:05:36

I don't know your setup, but for me == only looks at the line directly above, and when I'm doing things like renesting forms I need =- which fixes the entire top level form

Aron15:05:27

I think it was just easier to remember ==, I will try to use =i