1

Regex substitutions

2

When using regexes to perform substitutions in VIM you might have noticed that they quickly become unreadable. You have

3

to escape almost every special character.

4

5

If you, like me, prefer to use extended regular expressions you can start your substitutions with \v to enable something

6

called "very magic" mode. That means that all ASCII characters expect 0-9, a-z, A-Z and _ have special meaning.

7

8

As an example lets just use a regex group to quote the first 4 consecutive characters on every line:

9
:%s/\v([a-z]{4})/"\1"
10

11

Here is an example of what that looks like in my current buffer:

12

13
VIM substitution
VIM substitution using regex
14

15

Unfortunately, there isn't a setting to enable very magic mode by default.

15

16

The end

17

I usually tweet something when I've finished writing a new post. You can find me on Twitter

18

by clicking 

normalintroduction.md
||17:74

Recently Edited

Recently Edited

File name

Tags

Time to read

Created at

context

  • go
  • context
8 minutes2024-02-28

circular-buffers

  • go
  • concurrency
  • data processing
5 minutes2024-02-04

go-directives

  • go
  • compiler
  • performance
4 minutes2023-10-21

async-tree-traversals

  • node
  • trees
  • graphs
  • typescript
19 minutes2023-09-10

All Files

All Files

  • go

    5 files

  • node

    2 files

  • typescript

    1 file

  • frontend

    1 file

  • workflow

    7 files