Is there a command to paste (p) text with space inserted before that text like in join?

I don't want to achieve that by mapping.

Normally p pastes text right in the cursor's position in Normal Mode.

Switching modes, and inserting space manually everytime can be frustrating.


In .vimrc use a leader key and specify as follows:

nnoremap <leader>p li<space><esc>p

(leader-P to insert buffer after the cursor, adding a single space before the buffer.)


Use @p.

Prerequisite: .vimrc needs to contain this line (add it):

let @p='i ^[p'

You're saying: when I press @p you

  • press i for me so that you enter INSERT mode, then
  • insert a space, then
  • press ESC (^[ means ESC) to get back to NORMAL mode, then
  • press p to do the paste.

You're in NORMAL mode when it's done.

In case you haven't worked with registers yet

p is a register. Think of a macro consisting of anything you could do with your hands using the basic vim commands, typing and switching modes included.

Use the q command to define register contents (the recording status in the left bottom corner is for that).

  • This seems to literally insert "^[" into the text. Is there some special escaping I need to apply to .vimrc? – Charlie Dalsass Nov 17 '17 at 16:37
  • @CharlieDalsass You can insert a literal escape with Ctrl-v Esc or Ctrl-v Ctrl-[. – brhfl May 7 '18 at 17:16
  • 2
    @CharlieDalsass, alternatively, you can use one of Vim's "special characters" for this: :let @p = "i \<Esc>p" – Rich May 8 '18 at 8:40
  • @Rich, thanks I was having trouble with the escaping so I came up with the solution below. Didn't realize it was that simple! – Charlie Dalsass May 8 '18 at 12:38
  • 1
    I'm pretty sure I'm gonna start using registers on a daily basis thanks to your answer. Real thanks. – Stephane Rolland May 26 '20 at 6:15

As you have stated in your question, you don't want to use a new mapping for this. (I'm also more in favour of "vanilla" vim key-bindings if possible, so I can use my muscle-memory on other systems aswell)

The following vim keys let you paste with an additional space, without the need to leave insert mode for pasting:

a) Paste after a word somewhere in the middle of the line

  1. go to end of word with e
  2. press a to go into insert mode directly after word
  3. press space to insert space after last character
  4. press CTRL-r (cursor turns into ")
  5. press " for the last copy register (or 0 for the second-to-last, or + for system clipboard register,...) (*)

b) Paste at the end of current line

  1. press A to go directly into insert mode at the end of line
  2. press space
  3. press CTRL-r (cursor turns into ")
  4. select preferred register (*)

(*) To see all the copy registers use the command :registers

Also, :help i_CTRL-R might be worth a read.

Your Answer

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