Skip to content

Fixes case switching keybinds gu and gU so they dont chew up newlines - #1381

Closed
Nomarian wants to merge 1 commit into
martanne:masterfrom
Nomarian:fixcase
Closed

Fixes case switching keybinds gu and gU so they dont chew up newlines#1381
Nomarian wants to merge 1 commit into
martanne:masterfrom
Nomarian:fixcase

Conversation

@Nomarian

@Nomarian Nomarian commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #1238 #1320

| tr does the appropriate behavior but gawk supports other languages. so gawk is used

This makes it unportable, but if portability is desired, then | tr should be used and if which gawk returns true then gawk is used.

@Nomarian Nomarian closed this Jul 31, 2026
@Nomarian Nomarian reopened this Jul 31, 2026
@Nomarian Nomarian changed the title fix case switching keybinds gu and gU so they dont chew up newlines Ameliorates case switching keybinds gu and gU so they dont chew up newlines Jul 31, 2026
@Nomarian Nomarian changed the title Ameliorates case switching keybinds gu and gU so they dont chew up newlines Fixes case switching keybinds gu and gU so they dont chew up newlines Jul 31, 2026
@Nomarian Nomarian changed the title Fixes case switching keybinds gu and gU so they dont chew up newlines Ameliorates case switching keybinds gu and gU so they dont chew up newlines Jul 31, 2026
@Nomarian Nomarian changed the title Ameliorates case switching keybinds gu and gU so they dont chew up newlines Fixes case switching keybinds gu and gU so they dont chew up newlines Jul 31, 2026

@rnpnr rnpnr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need something so complicated:

awk '{print tolower($0)}'

should do the trick. You don't need to mess with the field separator or force gawk.

Personally I think we should just axe this whole passing off text editing functionality to external tools but that's a different story.

@Nomarian

Nomarian commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

It is necessary because print adds a newline. (so selections are not usable) So you must use printf or ORS="". But then you have a problem with RS="", which is that awk has this weird thing that eats away the last newline before EOF. This is an all AWKs thing

Now that I think about it, gawk can use \0 in RS, so if its that.

@Nomarian Nomarian closed this Jul 31, 2026
@rnpnr

rnpnr commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Frankly I think it's a problem with the way vis handles the result. But we can't really fix here without breaking every other use of vis_pipe (including from the user perspective).

Like I said, this whole passing off text editing tasks to external programs needs to be thrown away. It's not bloat for a text editor to perform text edits.

@Nomarian

Nomarian commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

No no, its fine, its awk, awk is the problem. Both sed and tr work perfectly well to transform text, take a bunch of text, transform it, print it out, its a simple gsub() call.

; echo this | tr -s '[:lower:]' '[:upper:]' | wc
      1       1       5

; echo -n this | tr -s '[:lower:]' '[:upper:]' | wc
      0       1       4

; echo -n this | sed 's/this/that/' | wc
      0       1       4

; echo this | sed 's/this/that/' | wc
      1       1       5

But awk does not work this way, awk reads a chunk of text until it hits the the record separator (RS), and it throws away the separator itself, you don't know if there is a RS, which means this is tricky (and wrong)

; echo this | awk 'BEGIN {ORS=""} {print toupper($0)}' | wc
      0       1       4
; echo -n this | awk 'BEGIN {ORS=""} {print toupper($0)}' | wc
      0       1       4

gawk is the only one that tells if there is an RS by saving it in RT (record terminator), but this is gawk specific.

; echo -n this | gawk 'BEGIN {ORS=""} {print toupper($0) RT}' | wc
      0       1       4
; echo this | gawk 'BEGIN {ORS=""} {print toupper($0) RT}' | wc
      1       1       5

if RS is multiple characters, it can be a regex, which means this is also possible

; echo -n '^$hi^$' | awk 'BEGIN {RS="^$";ORS=""} {print toupper($0) RT}' | wc
      0       1       6
; echo '^$hi^$' | awk 'BEGIN {RS="^$";ORS=""} {print toupper($0) RT}' | wc
      1       1       7

This is by far the best, most portable solution, there is one awk that does not support RS to be a regex (goawk), but that's also not the default anywhere.

I will keep using this last one for a while and see if there's a pitfall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V+u removes new line

2 participants