I know that in insert mode CTRL-Y can insert the character above the cursor.
Is there a way of inserting the word above the cursor in insert mode ?
I know that in insert mode CTRL-Y can insert the character above the cursor.
Is there a way of inserting the word above the cursor in insert mode ?
With a help of vimscript you might have following:
func! InsertWord()
" get previous line number
let prevline = line('.')-1
" get the line from current position to the end
let rest_of_line = strcharpart(getline(prevline), virtcol('.')-1)
" if cursor was on a space, return 1 <C-y>
if rest_of_line[0] == ' '
let cnt = 1
else
" otherwise count number of chars till the space and return that number of <C-y>s
let end_of_word = substitute(rest_of_line, '^\(\S\+\).*', '\1', '')
let cnt = strchars(end_of_word)
endif
return repeat("\<C-y>", cnt)
endfunc
inoremap <expr> <c-b> InsertWord()
What you can do via a series of commands, is as following:
ESCkyaw or yiwjIn short, :inoremap ,<C-Y> <ESC>kyiwjPa should work.
You can change a few things here and there according to your choices.
I would do that with mouse clicks. First highlight the word (this could be done with a double-click of the mouse) and then move the mouse to where you want to insert and press middle button of the mouse.
col()tovirtcol()and now it also works for non-latin too. Not sure about CJK though, can't test it :) – Maxim Kim Sep 09 '20 at 06:56