You can do a literal insert of register contents through :help i_CTRL-R_CTRL-R
, combined with the expression register (:help quote=
) to reference the variable:
execute "normal! i\<C-r>\<C-r>=text\<CR>\<Esc>"
Note that newlines will appear as ^@
; if the variable does not contain any other special characters, you could switch to :help i_CTRL-R
, which does interpret the variable contents as types (and therefore inserts a newline, but would also interpret stuff like Home etc.)
If you know that the variable contents are just plain text (without any special control characters), you could also just append the variable contents as-is and conclude with <Esc>
:
execute "normal! i" . text . "\<Esc>"
Or use the low-level setline()
, splicing in the text at the cursor column via string manipulation:
let line = getline('.')
call setline('.', strpart(line, 0, col('.') - 1) . text . strpart(line, col('.') - 1))