How to remove the last character in each line using vim

I have a file:

12345a 123456b 1234567c 12345678d 123456789e 

How to delete the last character in each line.
And the file will be

 12345 123456 1234567 12345678 123456789 
+5
source share
3 answers

You can use :%s/.\{1}$// to remove 1 character from the end of each line.

+18
source

Use the command :g :

 :g/^/norm $x 
  • ^ matches every line that will work.
  • norm is short for normal , before the normal command you want to execute.
  • $x move to end of line and delete character in normal mode
+2
source

:%normal $x

  • : puts you in command line mode.
  • % is a range representing the entire file
  • normal says we run the normal mode command
  • $x removes the last character in the string

Some overlap with other answers, but for me this text is read most simply.

0
source

Source: https://habr.com/ru/post/1245913/


All Articles