此信息将进入文档页面,并且很快就会出现。该文档最终应在http://yi-editor.github.io/上提供。一旦启动并运行,这应该是初学者的最佳文档。由于这可能需要一段时间,我会在这里尝试为您解答。
这应该是一个很好的配置。
import Yi
import Yi.Keymap.Vim
import qualified Yi.Keymap.Vim2 as V2
import qualified Yi.Keymap.Vim2.Common as V2
import qualified Yi.Keymap.Vim2.Utils as V2
import Yi.Hoogle (hoogleSearch)
main = yi $ myConfig
myConfig = defaultVimConfig { defaultKm = myKeymap }
myKeymap = v2KeymapSet $ myBindings
myBindings :: (String -> EditorM ()) -> [V2.VimBinding]
myBindings eval =
[ nmap "Y" (eval "yy")
, nmap' (leader "h") (hoogleSearch)
, imap "<End>" (withBuffer0 moveToEol)
]
-- Don't read the following, it's not important.
-- Boilerplate begins here
v2KeymapSet :: ((String -> EditorM ()) -> [V2.VimBinding]) -> KeymapSet
v2KeymapSet myBindings = V2.mkKeymapSet $ V2.defVimConfig `override` \super this ->
let eval = V2.pureEval this
in super {
V2.vimBindings = myBindings eval ++ V2.vimBindings super
}
nmap x y = V2.mkStringBindingE V2.Normal V2.Drop (x, y, id)
imap x y = V2.VimBindingE (\evs state -> case V2.vsMode state of
V2.Insert _ ->
fmap (const (y >> return V2.Continue))
(evs `V2.matchesString` x)
_ -> V2.NoMatch)
nmap' x y = V2.mkStringBindingY V2.Normal (x, y, id)
leader str = "\\" ++ str
-- Boilerplate ends here
不要担心样板。我真的认为这应该内置于易。忽略样板,配置看起来非常简单。
了解 nmap、imap、nmap'、eval 和 leader 很重要。
nmap 和 imap 类似于你在真正的 vim 中使用的。nmap 在 vim 的正常模式下映射一个键,而 imap 在 vim 的插入模式下映射一个键。
eval 可以评估击键。因此,带有 nmap "Y" 的行使正常模式下的 Y 执行与正常模式下 "yy" 相同的操作。这是重新绑定键的好方法。
领导者,简单地将领导者密钥定义为\。所以,现在,(leader "h") 仅仅意味着按下 \h。
nmap' 是必需的,因为有 EditorM 函数和 YiM 函数。nmap 适用于 EditorM,nmap' 适用于 YiM。理解这一点需要一些关于易的工作原理的知识,我不会深入探讨。为简单起见,hoogleSearch 函数的类型为 YiM,因此您需要 nmap' 。
这应该为您提供使用 Vim 键盘映射扩展 Yi 的基本布局。
使用这个配置,\h 应该触发 hoogleSearch,因为我们使用 nmap' 绑定它。
将键映射添加到 mkKeymap 和cleverMode 之间的区别在于,将其添加到cleverMode 仅在haskell 文件中启用键映射,而将其添加到mkKeymap 则将其添加到Yi,而不管您正在编辑哪个文件。当你刚开始接触易时,你可能不会太在意这个。
我希望这会有所帮助。如果您有任何问题,请随时在 github 上将其作为问题提及,或在 IRC 上跳转到 #yi。