Search code examples
vimscripting

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


I'm writing a Vim script. How can I get the word under the cursor and the text of the current line?


Solution

  • You can with expand and getline:

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