Jump to content
Toontje

How to send commands to vim?

Recommended Posts

I am still learning so bear with me...

 

I am building a workflow which is taking information from a text document open in vim and pasting it in a browser. For this, in vim, i have to enter a command string like njyt@yt.y$.

How do i do this in Alfred? I now have 9 key combo objects with 1 letter each, but there must be a better way to do this. Or not?

Share this post


Link to post
On 12/9/2019 at 1:55 PM, Toontje said:

How do i do this in Alfred? I now have 9 key combo objects with 1 letter each, but there must be a better way to do this. Or not?

 

You can send keystrokes with AppleScript, but that’s just the same solution in another way (though it does reduce your nine objects to one).


But emulating keystrokes is a poor solution that should only be used as a last resort. The proper way to achieve this would be to code the operation in vim.

Share this post


Link to post

How about if i want to send a URL to an already open browser? Or a string to a text input box in an application? That's the same use case, IMHO.

Share this post


Link to post
1 hour ago, Toontje said:

That's the same use case, IMHO.

 

Only superficially. What matters is which tools are available in each case, and simulating keypresses via AppleScript is, generally speaking, the worst tool for the job.

 

If the application offers a proper API to achieve what it is you're trying to do, that is always a better, more reliable option. And vim does.

 

Why are you firing 9 different keystrokes at vim when you can use something like nmap <F4> njyt@yt.y$ in your vimrc to map your command to a single keystroke?

Share this post


Link to post
16 minutes ago, deanishe said:

If the application offers a proper API to achieve what it is you're trying to do, that is always a better, more reliable option. And vim does.

Many applications don't. Please, enlighten me on the idea why it is possible to send one keystroke from Alfred, but not multiple (a string).

Share this post


Link to post
2 minutes ago, Toontje said:

Please, enlighten me on the idea why it is possible to send one keystroke from Alfred, but not multiple (a string).

 

I don't know what you mean. You can send as many keystrokes as you want. It's just very cumbersome because Alfred isn't really designed for sending long sequences of keystrokes. Vim's API is, which is why it's a better choice.

 

4 minutes ago, Toontje said:

Many applications don't.

 

And in those cases, you don't have much choice but to simulate keypresses. This is not one of those cases.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...