Ben Rich
Ben Rich

Reputation: 11

Deleting ith-jth character on every line in vim?

I'm currently trying to streamline how I edit my files, and I need to figure out a way to delete the 2nd-10th character of each line, preserving the first character of each line.

I know you can delete the first N characters of every line with :%s/^.{0,N}// , but I don't know how to make the first match to be second character of the line, instead of just the beginning of the line as expressed with ^

Sorry if this is a duplicate, I couldn't find any other questions that helped me with this.

Upvotes: 1

Views: 390

Answers (2)

Roger
Roger

Reputation: 193

Unless there are other conditions you can try

:%norm l9x

Clarification: run a "normal command" on every line that is "go one character to the right and delete nine characters".

It's a small 'L' in front of the '9', not a digit. ;-)

Upvotes: 1

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627119

I understand you need to remove nine characters beginning with the second char on each line.

You may use

:%s/^.\zs.\{9\}//

Details

  • ^ - start of a line
  • . - any one char
  • \zs - "lookbehind" alternative, dropping the text already matched so far
  • .\{9\} - any nine chars.

Upvotes: 2

Related Questions