helix
helix copied to clipboard
Language specific keymaps
It would be useful to be able to add to one of the config files (config.toml or languages.toml?) a language specific keymap that overrides the standard commands.
For example it could be something like this:
config.toml
[keys.normal]
space = { m = ':sh foo' }
languages.toml
[[language]]
name = "rust"
[language.keys.normal]
space = { m = ':sh bar' }
[[language]]
name = "haskell"
[language.keys.normal]
space = { m = ':sh baz' }
Is this useful for keymaps other than binding :sh commands? I can't think of a use-case other than trying to use the same key to run a build or test for different languages. And that use-case could be solved with https://github.com/helix-editor/helix/issues/3134 and some scripting
I can think of other use cases like shortcuts for common things specific to languages (adding pipelines to langs like elm/elixir. creating lambdas. anything that gets boring, could use movements based on treesitter, etc)
Also, even snippets using sh can be quite different between languages and it would be better to make these work without setting up just/make files - just ny own opinion but I rather not change projects just for my editor needs.
Another use case is that I need sometimes to do full rebuilds on Haskell and Purescript.
On Haskell I'm sending a command to a running ghci instance (so I'm using a :sh command).
On Purescript I have to send an LSP command (right now I'm using some custom code, but something like https://github.com/helix-editor/helix/pull/3140 could help).
I have the two commands bound to different keys, but I'd obviously like them to be on the same one.
This would work great for me as well because my Godot C# projects differ a bit from my standard C# projects. While dotnet build doesn't mind me passing in arbitrary properties, configuring a keybinding to run a build applies it globally, leaving me with a build command binding that only functions in my C# projects and fails for anything else.
Editor configuration merging would fix this for me, but this solution would work just as well because language config merging is already implemented.
This feature would be very helpful for me.
To give one more use-case:
I am using a hotkey to select the contents of a line without the newline at the end. In languages that use a ; or other symbols at the end of each line I would like to exclude these as well. Another example would be \\ for a newline in latex where I always end a line if I place a \\ somewhere. So I would configure the same keybind for every language to select exactly the contents I need from a line.
Isn't this a dupe of #836?
Also, how would this work with multi-lang files/selections (e.g. vue, svelte)?
Ah yeah I agree, #836 is more general and should cover this. I think that's probably how this should be solved in the future: language specific config of any sort rather than just keybindings.