Reputation: 3172
In my function I want to paste some generated text there at the position of the cursor (in insert mode). I am using put
to do so, however it pastes it on a new line. Is there a way to make put paste it on the same line? If not what is the proper command ?
Upvotes: 2
Views: 2565
Reputation: 40603
Where is the text to be inserted stored?
Edit
So, per your your comment, the text is stored in a variable. Assuming, the variable is g:text
, then, while in insert mode, you press ctrl-r
followed by =
followed by g:text
.
See also help i_CTRL-R_=
I leave the old answer here. Maybe someone else comes accros and finds it useful:
Assuming, it's in a register (as per your mentening :put
), you press CTRL-R
and then register name (for example a
) - (while being in insert mode).
Upvotes: 0
Reputation: 172758
You cannot use :put
, it will always use a new line. You have the following options:
:execute "normal! amy text\<Esc>"
. This needs :execute
to properly leave insert mode.:let @@ = 'my text'
Then, use :normal! p
(or P
, optionally with prepended motions to position the cursor). Alternatively, use the expression register: :execute "normal! \"='my text'\<CR>"
<C-r>{register}
or <C-r>={expr}<CR>
.:setline()
, splicing in the new contents into the existing (getline()
) line with the help of strpart()
.The first ones are easier, and usually what you want. The last is using a lower-level API, therefore more involved to use, but it doesn't trigger any messages, clobbers register contents, creates a separate change for undo, etc.
Upvotes: 6