On 2020-10-10, L A Walsh wrote: > Sometimes, I get some unformatted text, like HTML or XML that has all > the newlines removed. > > To make it easier to read, I'll sometimes add newlines and pair > up adjacent tags, using something like: > > :%s/>/>^M/g > :%s/<\([^>]\+\)>\n\([^>]\+\)<\/\1>/<\1>\2<\\\1> > > But then I have an unindented file like: > > <taga> > <line> > <tagb>xxx</tagb> > <tagc>yyy</tagc> > </line> > </taga> > > Where if I had typed it in by hand, with auto indent and syntax set, I'd > get: > > <taga> > <line> > <tagb>xxx</tagb> > <tagc>yyy</tagc> > </line> > </taga> > > ---- > To get the above, for very short examples, I can just > join 1+2nd line, then hit enter with cursor before "<line>", join nxt lines > and hit enter and so on. > > A __kludgy__ way for longer methods is to put the original in a file, > then in a non-paste aware TTY running vim, I can put all of the code > in my cut buffer, and paste it into the TTY window. It then acts like > it would if I'd typed it in, as it is unaware of the paste-mode (play > with paste/nopaste mode). > > How can I just reformat the file as if I'd just typed it all in by hand > without making use of a TTY window running vim and pasting all the text? > > Is there a format-type command as there is for text, where I can set > 'tw' (:set tw=72), select a paragraph or whole page, and use: > > :gqap to reflow the text. > > Thanks MUCH, if there is an easy command to do this!
I don't know of a way to do that with one command, but I usually do the newline insertion much as you do, then execute the following normal-mode command. gg=G See :help = You might also search the web for HTML Tidy. I think it will reformat an HTML file. Regards, Gary -- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201011061024.GA9889%40phoenix.