I'm trying to write a vim script. How can I get the word under the cursor and the text of the current line? I want to use it in my script, thanks.
In normal mode, move the cursor to any word then press * to search forwards for the next occurrence of the word under the cursor, or press # to search backwards. * or # search for the exact word under the cursor: searching for big would only find big and not bigger .
Press the Return key to move the cursor to the beginning of the next line down.
Press 0 to go to the beginning of a line, or ^ to go to the first non-blank character in a line.
You can with expand and getline:
let wordUnderCursor = expand("<cword>") let currentLine = getline(".")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With