What is the quickest way to un-doublespace in Vim, without using a regex?
There's gotta be a way without regexes, by using
If you're on linux, you could call an external program to filter a range of
lines (here I filter all of them with
:%! awk NF
In the above awk command, NF indicates the total number of fields, and hence this prints only non-blank lines, since in blank lines NF is 0 and evaluates to false.
Not sure if it's faster, but it's a different way (note this will just remove all blank lines from the document).
Use a recursive mapping. Define it with
:nmap <F2> gg}gJ<F2>
and then press F2. The mapping will go to the start of the file (
gg), search for the next empty line (
}), and try to to join the empty line with the next line, respecting leading indent (
gJ can join an empty line with the next line, the mapping will continue and call itself recursively (
<F2>); otherwise it will abort.
Note that this mapping will keep all empty lines at the start of the file and will reduce two or more empty lines at the end of the file to one empty line.