VIM is my favorite editor for nearly everything. Even I use it since 1996 there is still much to learn about it.
Today I wanna share my latest VIM knowlegde gain 🙂
The challenge is: How do I put incrementing number in front of each line?
The solution is:
let c=0|,$ g/^/ let c=c+1|s/^/\=c/
- define a variable “c” and initialize it with 0
- start at the current line until the last on the file “,$” (sure you can choose what ever you need)
- “g/^/” do it for all lines matching, thought I do it for all lines because every line has a beginning 🙂
- increment the varialbe c by 1 “let c=c+1”
- replace the begining of the line with the varialbe. to use the varaible you need to reference it like this “\=c”
Quote: “Share knowledge, gain wisdom” (Thomas Rieder)