Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

scripting

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.

like image 245
user133580 Avatar asked Jul 12 '09 06:07

user133580


People also ask

How to search for a word in cursor in vim?

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 .

How to move cursor to next line in vi editor?

Press the Return key to move the cursor to the beginning of the next line down.

How do you go to the beginning of a line in Vim?

Press 0 to go to the beginning of a line, or ^ to go to the first non-blank character in a line.


1 Answers

You can with expand and getline:

let wordUnderCursor = expand("<cword>") let currentLine   = getline(".") 
like image 153
Christian C. Salvadó Avatar answered Oct 01 '22 07:10

Christian C. Salvadó