vimvim-registers

vim - how do I yank to register inside a function?


I am perplexed how to use the registers from inside a function. For example, if I want to yank the current word to register "k", from inside vim, I would use the command/keystrokes

"kyw

But this does not work from inside a function: " starts a comment:

function MyFunction()
  "kyw
  "^^^ does not work because it is a comment...
  let @k="I can set register k directly to text..."
  " but that's not the same
  yank k "I can yank an entire line, but still not the same
endfunction

Is there a way to do this without changing the comment option (would that even work?) Thanks; I have been hitting my head against this for an entire day.


Solution

  • Use either