I have a huge file that I would like to format using Vim. For that, I would like to delete the newline characters at the end of every line.
For example,
I
want
this
to be
just one
line
should become
I want this to be just one line
I was thinking of doing it via the following command:
:%g/^/norm!‹a keyword that deletes the \n›
but I just don't know which keyword might work for that, to automate the pressing the Del key on every on every line.
Thanks in advance!
The most idiomatic way of joining all lines in a buffer is to use
the :join
command:
:%j!
(Remove the !
sign if you want Vim to insert space between joined
lines. From the wording of the question I assume that you do not want
to add spaces.)
The same could be done interactively, if you prefer:
ggVGgJ
(Again, use J
instead of gJ
if you want to separate joined lines
with spaces.)
Another option is the :substitute
command:
:%s/\n//
ggVGJ
Broken down:
gg
: move to line 1;V
: enter visual mode;G
: move to last line;J
: join selection to single line.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With