Jump to content

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?

Link to comment
  • 2 weeks later...
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.

Link to comment
  • 1 month later...
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?

Link to comment
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).

Link to comment
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.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...