user133580
user133580

Reputation: 1509

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?

Upvotes: 55

Views: 14831

Answers (1)

Christian C. Salvadó
Christian C. Salvadó

Reputation: 828200

You can with expand and getline:

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

Upvotes: 79

Related Questions