News for hackers. Stuff that matters.
Re:My Favorite Vim Oneliners for Text Manipulation by schaefer on Saturday August 05, 2023 @08:07PM (#37017553)
in command mode: gqq

Reformats the current long line into a paragraph of the specified width. If a word overruns the column width limit, the entire word is moved to the next line.

Re:My Favorite Vim Oneliners for Text Manipulation by 000ooo000 on Saturday August 05, 2023 @08:42PM (#37017762)
Awesome, thank you. I'm forever manually adjusting block comments to be a sensible width so this will help. Probably asking a bit much but do you know if there's a command that can operate on a visual line selection and do the same? e.g. I come across a block comment, add to it, then want to re-width it. Worst case, I guess I could create a command to collapse the lines first then run gqq.
Re:My Favorite Vim Oneliners for Text Manipulation by nerdponx on Saturday August 05, 2023 @09:19PM (#37018002)
The command you want is just gq. In normal mode it accepts a motion, eg gqip or gq}. And it works in visual mode as well. The gqq command is a special case for the current line. Personally I use https://github.com/kana/vim-textobj-line which defines a text object for the current line and maps it to _, so gq_ also formats the current line.

See here for relevant documentation: https://neovim.io/doc/user/change.html#formatting

Re:My Favorite Vim Oneliners for Text Manipulation by nkouevda on Sunday August 06, 2023 @12:16AM (#37018938)
fyi _ is a built-in motion; that plugin defines a couple others: il and al, which are specifically characterwise (vs. _ can be either that or linewise)

gq is a linewise operation anyway, so gq_, gqil, and gqal all have the same effect

Re:My Favorite Vim Oneliners for Text Manipulation by nerdponx on Sunday August 06, 2023 @02:53PM (#37025288)
Wait really? Is that new? I could have sworn it wasn't back when I first started (Vim 7 era).
Re:My Favorite Vim Oneliners for Text Manipulation by sdkgames on Sunday August 06, 2023 @12:17AM (#37018942)
if you have fmt (a console program from coreutils, on Linux it's usually preinstalled) then

1) mark your lines (Shift+v then move your cursor)

2) press ':'

3) '<,'> !fmt -w 80

In the similar way I also use column to format text.

Re:My Favorite Vim Oneliners for Text Manipulation by coliveira on Sunday August 06, 2023 @12:59AM (#37019106)
gq after you created the visual line selection.
Re:My Favorite Vim Oneliners for Text Manipulation by wilkystyle on Saturday August 05, 2023 @08:43PM (#37017767)
Also useful: gw is like gq but leaves the cursor where it is.
Re:My Favorite Vim Oneliners for Text Manipulation by cerved on Sunday August 06, 2023 @04:27AM (#37020015)
And it's inverse

  vipJ