How can I get the word under the cursor and the text of the current line in vim script?

Solution 1:

You can with expand and getline:

let wordUnderCursor = expand("<cword>")
let currentLine   = getline(".")