Friday, August 27, 2010

RE: Getting word under cursor

Gusman wrote:
> When I use try :echo expand("<cword>"), it return the correct value.
> But when I put it in a function like below:
>
> function! WordEcho()
> echo expand("<cWORD>")
> endfunction
> nnoremap <silent> <LocalLeader>k: call WordEcho() <CR>
>
> Then I type \k in normal mode, it return wrong value, but
> when I call it from prompt :call WordEcho(), it return correct value.

You are missing ':'. I think I have not correctly quoted your
text above because I think you are not posting plain text.
Please use plain text only on a mailing list.

The following works:

" abc def ghi
function! WordEcho()
echo expand("<cWORD>")
endfunction
nnoremap <silent> <F8> :call WordEcho()<CR>

Put cursor on 'def' and press the F8 key.

These tips may be useful:
http://vim.wikia.com/wiki/Search_for_current_word_in_multiple_files
http://vim.wikia.com/wiki/Search_using_quickfix_to_list_occurrences
http://vim.wikia.com/wiki/Find_in_files_within_Vim

John

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: