vim

mars0i 2023-03-02T17:58:27.899169Z

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.

tomd 2023-03-02T18:08:29.144709Z

gqi" ?

☝️ 2
mars0i 2023-03-02T18:43:56.211139Z

Thanks @tomd. 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.)

👍 1
dave 2023-03-02T19:09:51.038239Z

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?

tomd 2023-03-02T19:14:39.901219Z

gw doesn't move the cursor

tomd 2023-03-02T19:15:56.226859Z

Probably the better choice in most cases

2023-03-02T19:27:55.830279Z

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)

2023-03-02T19:28:29.315709Z

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

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

2023-03-02T19:29:54.578199Z

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 |

mars0i 2023-03-02T20:29:52.037329Z

Thanks @dave, @jkrasnay, @tomd. 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).

timo 2023-03-05T08:40:32.882009Z

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