2

How to put at end of line with vim?

I would like to use p to put some text at the end of the current line without moving the cursor.

Edit:

For example I would like to copy a word to the end of the line so I use yw to copy the word and then how can I put it to the end of the current line?

  • 2
    What do you mean? – user859 May 6 '16 at 10:17
  • 2
    If you want a mapping you could try this: nnoremap ,p m'yiw$p`` . Hit ,p and the word under the cursor should be pasted at the end of the line. You don't need the space at the end, it's here because I don't know how to format code containing a double backtick without it. – user9433424 May 6 '16 at 11:18
5

If you want your cursor back to its previous position after putting the text at the end of the line you could use marks:

ma$p`a
  • ma sets the mark a to the current position
  • $p As explained is the other answers put the text at the end of the line
  • (backtick)a go back to the position marked by ma
3

You want to "put", not "print".

  1. Move the cursor to the end of the line with $.

  2. Press p to "put" the content of the unnamed register (what you yanked with yw) after the cursor.

See :help p, :help registers, :help :print.

  • yes, put sorry! However I would like to print to the end of line without moving the cursors. Is this possible? – Federico Ponzi May 6 '16 at 11:05
  • 4
    No. You need to move the cursor to where you want to put. – romainl May 6 '16 at 11:06
3

If I understand correctly, you want to put a word at the end of the line.

You can do that with:

$p

$ move the cursor to the end of the line, p put.

The print command on the other hand, is used to display lines of your file, e.g.

:1,2p "print the first and second line.

Ref:

  • :h p (put)
  • :h :p (print)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.