Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feedkeys not working? #27

Closed
nosami opened this issue Dec 30, 2013 · 11 comments
Closed

feedkeys not working? #27

nosami opened this issue Dec 30, 2013 · 11 comments

Comments

@nosami
Copy link

nosami commented Dec 30, 2013

Hi,

I am having trouble getting feedkeys to work. Not sure if it's an issue with the vspec plugin or if I am doing something wrong (My vimscript is pretty weak)

Here's an example :-

  it 'completes abcde'
    put! = 'abc'  
    call feedkeys("Ade\<esc>")
        sleep
    Expect getline(1) == 'abcde'
  end

Output :-

# Expected getline(1) == 'abcde'
#       Actual value: 'abc'
#     Expected value: 'abcde'
@kana
Copy link
Owner

kana commented Dec 31, 2013

You have to use :normal instead of feedkeys().

feedkeys() only pushes characters into the input queue. When Vim becomes idle and the input queue is not empty, Vim will take a character from the input queue and processes it as if user typed the character. And Vim will never be idle while running a test script, because Vim is always busy to execute each line in the test script.

While :normal {command} directly executes Normal mode {command}. This is the proper way to emulate Normal mode commands in a test script in most situations.

@nosami
Copy link
Author

nosami commented Dec 31, 2013

Thanks for the reply! That makes sense, but what I'm actually trying to do though is simulate triggering omnicomplete with <c-x><c-o> in insert mode. I don't think that's possible using :normal ?

@kana
Copy link
Owner

kana commented Dec 31, 2013

Try :execute 'normal!' "a\<C-x>\<C-o>".

@nosami
Copy link
Author

nosami commented Dec 31, 2013

I can't get that to work. Even if I try just :normal "a\<C-x>\<C-o>" manually (with quotes), it doesn't seem to do anything. I tried a bunch of different variations.

If I remove the quotes, then is inserted into the document. call feedkeys() does what I want (if I invoke it manually), I understand your explanation for why it won't work in a script though.

Thanks for your help. Maybe it's not possible.

@kana
Copy link
Owner

kana commented Dec 31, 2013

Don't remove :execute! Try :execute 'normal!' "a\<C-x>\<C-o>".

@nosami
Copy link
Author

nosami commented Dec 31, 2013

I should have mentioned, I tried that first of all before I started trying to change the command. It has no effect.

@nosami
Copy link
Author

nosami commented Dec 31, 2013

This doesn't seem to be a vspec issue. Feel free to close.

Thanks anyway!

@kana
Copy link
Owner

kana commented Dec 31, 2013

I confirmed :normal can invoke omni completion with the following steps:

filetype plugin on

describe ':normal'
  before
    enew!
    setfiletype html
  end

  it 'can invoke omni completion'
    execute 'normal!' "a<div i\<C-x>\<C-o>"
    Expect getline(1) ==# '<div id="'
  end
end

@kana
Copy link
Owner

kana commented Dec 31, 2013

If you still have troubles, please paste the actual test script you wrote. I couldn't give a proper advice without it.

@nosami
Copy link
Author

nosami commented Dec 31, 2013

Your script works for me too. Thank you so much for your time. I appreciate it!

I need to dig around a bit more to see what I'm doing wrong in my script.

kana added a commit that referenced this issue Feb 4, 2014
@kana
Copy link
Owner

kana commented Feb 9, 2014

I added notes on how to emulate user input into the document.
Since vspec runs a test script with a plain Vim like vim -u NONE -i NONE -N, plugins and filetype plugins are not loaded by default. So that I think the core problem you encountered that you didn't write :filetype plugin on in test scripts. You succeeded to trigger omni completion, but the current buffer didn't have filetype, so nothing happened.

@kana kana closed this as completed Feb 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants