Mirieri Mogaka
Mirieri Mogaka

Reputation: 561

Command to remove all white spaces in vim

I want to be able to remove all the white spaces in my txt file using vim

update reg04_rpt_animreg set birthdate = '      2016-01-21       ' where animalid = '   TZN000192803889  ';
update reg04_rpt_animreg set birthdate = '      2015-07-05       ' where animalid = '   TZN000192803890  ';
update reg04_rpt_animreg set birthdate = '      2011-12-12       ' where animalid = '   TZN000192803891  ';
update reg04_rpt_animreg set birthdate = '      2013-05-05       ' where animalid = '   TZN000192803893  ';
update reg04_rpt_animreg set birthdate = '      2013-04-02       ' where animalid = '   TZN000192803894  ';
update reg04_rpt_animreg set birthdate = '      2015-05-16       ' where animalid = '   TZN000192803895  ';

I have used the following command with vim but havent gotten my expected output

:g/^\s*$/d

Upvotes: 1

Views: 2735

Answers (2)

sidyll
sidyll

Reputation: 59277

If you're trying to trim spaces inside the single quotes only, this should work:

:%s/= '\zs\s*\(\S*\)\s*'/\1'/g

Upvotes: 1

icedwater
icedwater

Reputation: 4887

I think you're looking for the s command; :g/<regexp>/d deletes the whole line which matches <regexp>.

:%s/\s//g

This replaces all space-type characters (\s) globally (g).

Upvotes: 5

Related Questions