Consider the following function
function! AbbreviationsOpen()
"go to the first word of the last line
normal G
"store the word in the register named a
let @a = expand('<cword>')
"display the word in the command line
execute "normal :<C-R>a"
endfunction`
The last line of the above function (execute ...) is not taking any effect. However, if I use the following function
function! AbbreviationsOpen()
"go to the first word of the last line
normal G
"store the word in the register named a
let @a = expand('<cword>')
endfunction`
and then press the following keys
:<ctrl>ra
then I do get the word appearing on the command line.
So can somebody help me as to why the above function does not work?
Also, I do not want to use a register. I'd like to achieve this using a variable. So the the function I want to write should look like.
function! AbbreviationsOpen()
"go to the first word of the last line
normal G
"store the word in the register named a
let var = expand('<cword>')
SOMETHING
endfunction`
matchstr(getline('$'), '^\S\+')
to avoid side effects<C-R>
in the last line of your function. Unless you entered it by pressingCtrl-V
followed byCtrl-R
then that won't work, either. An easier way to use control characters in a string is to use Vim's special escapes:"\<C-R>"
evaluates to a singleCtrl-R
character. See:help string
.