question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Language mode-specific key binding?

See original GitHub issue

I’d like to map a keybinding for a specific language mode. Specifically, I’d like to map j to gj, as shown in the README, but only for Markdown.

I’ve tried a couple variants of the when clause using, for example, resourceLangId == markdown, but since that’s used for mappings (and not settings) it doesn’t seem to be an option.

Is what I’m trying to do even possible? I have several custom filetype mappings in Vim and would like to carry that approach over to VSCode.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:15
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

8reactions
adipurnamacommented, Sep 5, 2021

adding editorLangId == <file_type> at when clause seems to be working now.

e.g.

  "vim.normalModeKeyBindingsNonRecursive": [
     ...
     {
	"before": [ "t", "t" ],
	"commands": [ "testing.runAtCursor" ],
	"when": "editorLangId != go && editorTextFocus && !inReferenceSearchEditor && !isInEmbeddedEditor",
     },
     {
	"before": [ "t", "t" ],
	"commands": [ "go.test.cursor" ],
	"when": "editorLangId == go  && editorTextFocus && !inReferenceSearchEditor && !isInEmbeddedEditor",
     },
     ...
   ]
4reactions
jeremyjhcommented, Jan 22, 2019

@jpoon you can get the file name though right? This would allow for people to have ftdetect style bindings. It is surprising this would not be on the roadmap for a vim emulator.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mastering Key Bindings in Emacs
Binds a key to the local keymap used by the active buffer, unlike define-key which takes an explicit keymap to bind a key...
Read more >
Set custom keybinding for specific Emacs mode - Stack Overflow
Though I know how to set a global key-binding in Emacs, I find it hard to even Google out the code for a...
Read more >
The Emacs Guru Guide to Key Bindings - Wilfred Hughes
Emacs is a modal editor, so most key bindings are mode-specific. ... but these commands usually work in any programming language!
Read more >
How to define mode-specific keys in evil-mode? [duplicate]
The standard way to set mode-specific keybindings in evil is to use: ;; default (define-key evil-insert-state-map (kbd "RET") ...
Read more >
Visual Studio Code Key Bindings
Rich Languages Editing. Command, Key, Command id. Trigger Suggest, Ctrl+Space, editor.action.triggerSuggest.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found