woland on Nostr: Did you know that you can replace a regex with unicode character in Vim? When is it ...
Did you know that you can replace a regex with unicode character in Vim? When is it useful?
When mass formatting a text. Such as replacing all instances of {...} with {…}. Or all dashes with en-dash or em-dash.
:%s/\.\.\./\=nr2char(0x2026)/gc
nr2char() replaces the matched regex with the character represented by its unicode value.
#vim #regex
Published at
2024-11-07 23:27:48Event JSON
{
"id": "9c89f639de28ad556dafd7c3d7791bffaf22f241fa0a162bf92843697dc11a35",
"pubkey": "8723291b2ab66e548a82e10640e0d8936d094d268a1d671bc4fb173268b79503",
"created_at": 1731022068,
"kind": 1,
"tags": [
[
"t",
"vim"
],
[
"t",
"regex"
],
[
"proxy",
"https://mastodon.bsd.cafe/users/wolandark/statuses/113444262257476388",
"activitypub"
]
],
"content": "Did you know that you can replace a regex with unicode character in Vim? When is it useful?\nWhen mass formatting a text. Such as replacing all instances of {...} with {…}. Or all dashes with en-dash or em-dash.\n\n:%s/\\.\\.\\./\\=nr2char(0x2026)/gc\n\nnr2char() replaces the matched regex with the character represented by its unicode value.\n\n#vim #regex",
"sig": "6252bae1b1b43bb3c9fced748ddc50cd0683c1135d63c39e8fbdfee971fedc394a5e1597e8e120806688e93682e27c5fe1033c1509fa0642afe2733b5e5c047c"
}