I would like to delete every double space in a file open in vim, how is this done?
e.g delete space here
a a
but keep the space here
a a
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
:%s/\s\{2,}//gWhere the elements are:
%ssubstitute in the whole file\swhat to substitute: a space\{2,}two or more occurrences//replace with nothing (i.e. delete)gdo it on every occurrence on the current line (not only on the first)The elements shall become clearer if you look at the anatomy of the substitute call:
So, the
PATTERNin our case is\s\{2,}, theREPLACEMENTis empty andFLAGSare justg. The range gets prefixed and is%which indicates the whole file. If you just want to do it on some lines, you could select the lines visually and then type:s....Edit:
In your question, you wrote that you want to
That’s what I answered. If you want to replace two and more spaces by one, the command would be