I have a JavaScript code written as a one long line and I want to re-format that so that each statement is written in one line. Is that possible using Vim? I tried the gqq and == commands and they didn’t work.
Share
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.
It will probably be easier to reformat using regexp first :
:%s/;/;\r/gc:%s/}/}\r/gc:%s/{/{\r/gcetc
to insert line return after ; or { }.
(if you are confident enough or the file is to long, do not use
cit will ask for a confirmation for each match)Once your file is split on different lines, you can use
gg=Gto get the correct indentation.As far as I know it is not possible to split a line on multiple lines with either gq or =