Vim icon indicating copy to clipboard operation
Vim copied to clipboard

Support `gw`

Open alexanderkjeldaas opened this issue 6 years ago • 10 comments

Describe the solution you'd like I need gw{motion} to work in order to edit plain text, like markdown.

Describe alternatives you've considered There are probably other vim commands that can be used, but gw is what I know.

alexanderkjeldaas avatar Jan 29 '20 08:01 alexanderkjeldaas

Oh, gw is like fill-paragraph in emacs, it will wrap long lines based on textwidth.

alexanderkjeldaas avatar Jan 29 '20 08:01 alexanderkjeldaas

Does gq do what you need?

max-sixty avatar Jan 29 '20 14:01 max-sixty

Yes it seems like gq does the same thing(?)

On Wed, Jan 29, 2020 at 3:57 PM Maximilian Roos [email protected] wrote:

Does gq do what you need?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/VSCodeVim/Vim/issues/4523?email_source=notifications&email_token=AACS3KIPAXWKYRUOJJUVIMTRAGKMTA5CNFSM4KNAU42KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKHPEDY#issuecomment-579793423, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACS3KPED3WL334NXNGNF6LRAGKMTANCNFSM4KNAU42A .

alexanderkjeldaas avatar Jan 31 '20 10:01 alexanderkjeldaas

http://vimdoc.sourceforge.net/htmldoc/change.html#gw

J-Fields avatar Jan 31 '20 15:01 J-Fields

Isn't the current action of gq actually more similar to the gw than the gq though? Except for the cursor position. Because gq is supposed to take into account the 'formatexpr' and 'formatprg' while gw isn't and in our case we don't have any of that, so if we changed the cursor situation this would be more like the gw. Or are we aiming to just get a gw that is equal to our gq but keeping the cursor? I don't know enough about this commands to know if the 'formatexpr' and 'formatprg' is even feasible to implement in VSCodeVim, maybe it's not.

berknam avatar Jun 12 '20 16:06 berknam

I agree that the current behavior of gq is a bit jarring to Vim users. As @berknam said, it behaves much more like gw (minus the cursor position).

In vim, I set formatprg to the appropriate formatting tool based on filetype.

autocmd FileType json setlocal formatprg="prettier --parser=json --stdin-filepath --"

Which allows me to gq{motion} (e.g. gggqG to go to top of file and format until end of file). This also works for Go, Terraform, SQL ...etc. See my dotfiles for reference.

I would be fine if gq worked in VS Code by essentially calling Format Document or Format Selection under the hood.

pbnj avatar Aug 20 '20 03:08 pbnj

What's the difference between =/equalprg and gq/formatprg in terms of intention?

J-Fields avatar Aug 20 '20 03:08 J-Fields

Per the equalprg and formatprg docs, the way I understand the difference to be is = is only concerned with indentation, while gq handles text formatting in general.

pbnj avatar Aug 20 '20 03:08 pbnj

Hmm so maybe we do the following?

  • Change gq to do what = currently does (Format Selection)
  • Change = to do Reindent Lines
  • Implement gw to do what gq currently does (reflow lines), but with correct cursor positioning

Then add equalprg and/or formatprg if someone complains for some reason.

J-Fields avatar Aug 20 '20 18:08 J-Fields

Change gq to do what = currently does (Format Selection)

That would be appreciated!

nickdesaulniers avatar May 12 '25 21:05 nickdesaulniers