1

I want do do a very simple script that visually selects the word under the cursor, and then calls another function (from an already existing vim plugin) that depends on this selection.

I've tried this:

function! ThisWord()
    normal! vaw
    " some other function that I'm not calling yet
endfunction

map <leader>a :execute ThisWord()<CR>

However, if for example I do this in the word 'main' (somewhere near the end of the file), it selects from the top of the file just up to the word in question (including it).

How can I select just the word under the cursor? Is this related to the '< and '> marks as mentioned here?

Or does the execute somehow work with a different set of coordinates?

Community
  • 1
  • 1
jcristovao
  • 554
  • 2
  • 12

2 Answers2

1

1) call a function by call Funcxxx()

2)

it selects from the top of the file just up to the word in question (including it).

was this done by the plugin function or your nromal! vaw?

3) '< '> are line based marks. you cannot use them for a selected word.

4) you should check the function in your plugin, what is the parameter. if it worked with range like '< '> you cannot select a word and pass to that function. Because the function may do something on the whole line.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • The call did it, thanks. It should be the normal! vaw to do it, I'm not even calling the other function yet. I'm still puzzled why it didn't work with the exec. I read [here](http://stackoverflow.com/questions/18178768/vimscript-call-vs-execute) that it executes as an `Ex command`. Does this imply any context changes? – jcristovao Nov 21 '13 at 15:49
  • An Ex command has to be specifically defined with `:com[mand][!]`; just being a function isn't enough. – echristopherson Nov 21 '13 at 22:44
0

You might try this instead of your normal command:

let s:wordUnderCursor = expand("<cword>")

Edit: It looks like I misunderstood the question.

Jeff
  • 1,787
  • 9
  • 14