Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove the last six characters of every line in Vim?

Tags:

vim

I have the following characters being repeated at the end of every line:

^[[00m 

How can I remove them from each line using the Vim editor?

When I give the command :%s/^[[00m//g, it doesn't work.

like image 339
Alisha Avatar asked Jul 10 '12 08:07

Alisha


People also ask

How do I delete a specific character in Vim?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command.


1 Answers

You could use :%s/.\{6}$// to literally delete 6 characters off the end of each line.

The : starts ex mode which lets you execute a command. % is a range that specifies that this command should operate on the whole file. The s stands for substitute and is followed by a pattern and replace string in the format s/pattern/replacement/. Our pattern in this case is .\{6}$ which means match any character (.) exactly 6 times (\{6}) followed by the end of the line ($) and replace it with our replacement string, which is nothing. Therefore, as I said above, this matches the last 6 characters of every line and replaces them with nothing.

like image 164
Conner Avatar answered Sep 28 '22 02:09

Conner