Fork me on GitHub
#vim
<
2023-03-02
>
mars0i17:03:27

I'm kind of embarrassed to ask this, but ... what tool/keymapping do you use to reformat docstrings? i.e. one edits a docstring, and now some lines are too long or too short, and you have to reformat the docstring paragraph: what tool do you use to do that automatically? What's embarrassing is that I've been using Clojure for years, and I still don't have a convenient way to do this! 🤷 I think I must just have missed something--because obviously everyone has to do it often--and I've never come across a keybinding or utility that does it. (Currently, I temporarily add empty lines above and below the docstring, and then use a standard paragraph formatter, and then remove the empty lines. Which is silly. I can make a vim macro out of these steps, but that seems silly, too. Because surely it's already been done.) I'm using conjure, but perhaps it's normally done using some other tool. I don't see anything in the Conjure docs.

tomd18:03:29

gqi" ?

☝️ 4
mars0i18:03:56

Thanks @UE1N3HAJH. The i" piece isn't working for me, but I understand the idea. I'll have to figure out what's going on with my config. (I see now that part of the reason I never learned this trick is that (a) I write text more often than code, (b) I started using vim so long ago that g and q were not mapped to anything--or not to anything I thought useful--so I created my own custom mappings for them for use with writing text [and got annoyed when Bram or someone created standard mappings later] so I've never used g or q in the usual way. Oh well.)

👍 2
dave19:03:51

I tend to use gw for this (e.g. gwi", or gww to just do the current line) I forget the difference between gw and gq -- does anyone here know?

tomd19:03:39

gw doesn't move the cursor

tomd19:03:56

Probably the better choice in most cases

jkrasnay19:03:55

I just visually select the paragraph I want to format and hit gq (that stopped working recently, though. Glad to learn that gw does the trick)

jkrasnay19:03:29

I tend to document function args in a little block like this:

foo | Doco for the `foo` arg
bar | Doco for the `bar` arg

jkrasnay19:03:54

To line up the pipes I visually select the args block and use the Tabularize plugin like this :Tab /|, which I have mapped to just |

mars0i20:03:52

Thanks @U0AHJUHJN, @U0DTSCAUU, @UE1N3HAJH. That's all very helpful. Now I just have to figure out my preferred approach (and mess with my config a little to create a new mapping because my fingers have permanently reassigned the meaning of g to something no one else uses).

timo08:03:32

You can format in vim with =. Check this out: https://vim.fandom.com/wiki/Format_a_code_block