1

In vimscript expand('<cword>') gives me the word under the cursor.

How can I get the word under the cursor starting at he current cursor location (skipping the word start).

5
  • Can I ask why? ye should do it, but moves the cursor.
    – D. Ben Knoble
    Commented Feb 15, 2019 at 15:17
  • I want to use the result of ye for fzf find, but without changing the cursor or my cut buffer.
    – ideasman42
    Commented Feb 16, 2019 at 0:32
  • Use a different buffer? "aye
    – jhnc
    Commented Feb 24, 2019 at 6:16
  • But how to extract this in vimscript?
    – ideasman42
    Commented Feb 24, 2019 at 10:26
  • Is there something open in your question? How can we help you further? Otherwise may be could accept a solution. It allows the question to rest :-) Commented Oct 14, 2023 at 3:26

1 Answer 1

1

Using vimscript: matchstr(getline('.'), '\k*', getpos('.')[2]-1).

getline('.') gets the current line, matchstrpos searches for the current keyword pattern \k* starting from the current cursor position from getpos('.'), where current cursor position is at the second index and we need to subtract 1 to index the search correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.