Custom Ex Command in Yi Editor

Posted on October 19, 2015 by Richard Goulter
Tags: programming.haskell, programming.yi, programming.editors

This is something I’ve mentioned before, but I see that I wasn’t entirely clear on how to achieve it.

In more detail, here are some notes on how to write a “Hello World” Ex-style command for the Yi editor.
– The exciting thing about this is it’s easier to write such commands for Yi than for Vim.

The following has been checked with v0.12.2 of Yi.

Compare: Yi.Keymap.Vim.Ex.Commands module. The ‘Reload’ command is the simplest. - This helps see how Ex commands for Vim-style Yi are parsed, and how they can map to an ExCommand, which is in turn responsible for an Action to execute.

See this gist for a full, working example, but for the code itself, the highlights would be:

helloWorld :: YiM ()
helloWorld = withCurrentBuffer $ insertN "Hello, world!"
parse :: EventString -> Maybe ExCommand
parse "helloWorld" = Just $ impureExCommand {
    cmdShow = "helloWorld"
  , cmdAction = YiA $ helloWorld
  }
parse _ = Nothing
import qualified HelloWorld as HelloWorld

...

main = yi $ defaultVimConfig {
    defaultKm = mkKeymapSet $ defVimConfig `override` \ super self -> super
            { vimExCommandParsers = myExCmdParsers ++ vimExCommandParsers super }
 }

myExCmdParsers = [HelloWorld.parse]

This is enough to get a “Hello World” example going.
For more sophisticated efforts, I’m guessing one would want to:


Newer post Older post