Can Vim do something to the effect of the paste -d ' ' shell
command, other then by running it via :r !paste -d ' '?
What are the native Vim commands that can be used for that, if any?
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.
First, let us consider a somewhat different but closely related
problem: appending one range of lines to another range immediately
preceding it. After solving it, we will return to the original
problem in the second part of the answer, and will show how the
original problem can be reduced to the suggested one.
1. Without restricting the generality, we assume that the first
block of lines (the one to append the second one to) starts on the
first line of the buffer, and that the cursor is located on the last
line of that first block. In this case, the lines can be joined using
the following short and efficient Ex command:
This
:globalcommand runs over the range of lines from the first tothe current one, sequentially executing two Ex commands:
''+m.and-j!. The former,:movecommand, deletes the line next to thatwhere the cursor has been positioned, and inserts it just below the
one currently being processed by the
:globalcommand. The latter,:joincommand, appends the just moved line to the one above (withoutadding or removing whitespace between them, because of the
!modifier).The construction of these commands takes advantage of two implicit
facts. First, before the command specified in a
:globalis executedon yet another line, the cursor is positioned at the first column of
that line. It means that the address referenced as
.corresponds tothe latest line on which the command is currently being run. Second,
the cursor position before sending a
:globalcommand to execution isadded to the jump list. Therefore, that location can be addressed in
ranges through the
'pseudo-mark (see:help :range).If it is needed to put a separator in between joined lines, one can
add a substitution command inserting it before
:joinis executed:There is an option of the default Vim sentence separation behavior
that is used when the
:joincommand is run without the!modifier:For details about that space-separation behavior, see
:help J,:help :join, and especially the paragraph that can be found by:helpg These commands, except "gJ".2. The technique is easily applicable to the problem in question,
since the initial situation can be narrowed down to the one we have
considered above. In order to do that, go to the buffer containing the
lines to append and copy them,
Then, switch to the target buffer containing the text to append to,
and paste the copied lines below the current contents of the buffer,
The above command combines two actions:
moving the cursor to the last line of the pasted text.
Upon that, one of the
:globalcommands proposed earlier can be usedimmediately. Of course, it is possible to issue both pasting and
transforming in a single run: