VIM Mode - Quality of Life Improvements

(For a good example of how all of the below can be done without having to parse an arbitrary vimrc, see IdeaVim plugin for intellij platform)

1. Support remapping VIM Esc key

I believe that most of people heavily using VIM do not actually use Esc as VIM Esc, but rather have it remapped to some key chord or combination so they don’t have to reach for Esc. Some common examples are chords like fd, jj, jk, etc.

2. Have an option to remap j=gj, k=gk, $=g$, ^=g^, 0=g^, etc

Because most of the lines in markdown paragraphs will span multiple screen lines, it is very hard to navigate text in VIM mode if there’s no support for g$ and g^ at all (start and end of screen line), and gj and gk, although being supported, are not remappable to j and k.

3. Minimal set of emulated extensions like vim-surround

Support a minimal number of quality-of-life extensions to vim that most of the users are using anyway (see ideavim for a sample list) - e.g., at the very least, just vim-surround.

4. Allow using monospaced font in the editor pane

With non-monospaced font, up/down navigation is extremely weird in VIM mode.

66 Likes

With regards to monospaced font, you should be able to do that using a custom CSS, no?

Totally agree on the others. I’ve found myself particularly missing vim-surround

4 Likes
  1. Can be done with CSS like Caketray said and even be more customized

For the rest it would be super nice, but I wonder how much is feasible since the Vim mode is just codemirror vim mode as a side effect of the editor being codemirror but not sure how much custom stuff you can build on top of that. Might be a case for the WYSIWYG editor features

1 Like

CodeMirror still supports some customization, e.g. you can do things like:

CodeMirror.Vim.map('jj', '<Esc>', 'insert')

It’s just a matter of exposing this somewhere in preferences, and maybe adding a checkbox for “use VIM visual navigation” that maps j to gj, k to gk, etc. Maybe a special editbox in preferences, ‘remap VIM Esc to’.

Same thing with CSS and font names - while it sure is customizable that way, as a user, the last thing I’d want to do is have to write some custom CSS to just change my editor font, it should be just a select box somewhere in preferences.

3 Likes

There is work to allow some customization without writing CSS not sure what will or won’t be included though but I would suspect font is one. Good to know for codemirror, maybe then the dev can expose that in some ways or like a plugins

Sadly the vim mode also does not support actions with motions like di( (delete inside parens) or yi[ (copy text inside [] ).

But I guess that’s a codemirror issue then?

6 Likes

I think the most important think for me would be integrating “search in file” with Vim’s / search command. I use / and n or N a lot navigating inside files.

3 Likes

Are you sure? It works for me. I can delete all wrapped with brackets for example.

1 Like

Interesting, di( works for you in Obsidian? I get the same behavior mentioned by @theduke. I just noticed that when the command fails, like di( for example, an error is logged to the console, Uncaught TypeError: cm.scanForBracket is not a function. which led me to this issue (Boostnote also uses CodeMirror), that issues mentions:

codemirror/addon/edit/matchbrackets.js is required when we use CodeMirror with Vim mode.

But if it’s working for you, then perhaps something else is going on.

Sorry, false alarm. I only deleted one word inside parents recently and that worked. But multiple words etc. do not work for me was well.

Same.

Thanks for the update. I hope this issue can be addressed soon.

1 Like

+1 to basic remapping. The vim-surround might be trickier; I didn’t see anything preexisting for CodeMirror. But my biggest VIM-grievance right now is I can’t set it to use the System Clipboard. I didn’t see anything out-of-the-box with CodeMirror so it’s likely a bigger ask. But I’d be super grateful!

I use Alfred.app’s clipboard manager very frequently so not using a shared copyboard is pretty frustrating. Worse, I lost a file from a bad cut and paste and no way to restore it.

2 Likes

Hi,

I have a small suggestion. I use the Vim’s pseudo normal mode a lot while editing text. So basically when I am in insert mode, I can press to be in normal mode for one stroke, press a key, and then I am back in insert mode.

I’m not really sure what is this called in the world of vim but I remember is as pseudo normal mode. I can invoke it with Ctrl-o

Is there plans to implement this feature? That would be cool.

Something I’d like is the ability to continue the list/todos when inserting a new line using O. If I’m in insert mode and press enter a new bullet/todo is added, but in normal mode using O simply adds a new line.

Peek 2020-07-30 12-34

11 Likes

+1000 for allowing users to remap ESC to jk or jj.

12 Likes

I would also LOVE to be able to customize vim. gj to j and gk to k for example.

Also, I if I just press and hold j or k, it doesn’t continuously scroll; I have to press the j or k keys every single time I want the cursor to go down or up. Is there some setting to allow for continuous movement by just pressing and holding the key? I thought this was default vim behavior. Maybe there’s something in my .vimrc that I put a long time ago that makes this happen. Any help would be greatly appreciated :slight_smile:

6 Likes

Deeper Vim integration will be amazing. Maybe after there is a plugin API, someone will use Neovim to actually embed a Vim editor directly in Obsidian.

9 Likes

Don’t know if this helps narrow down the issue. While using vim, I’ve found that commands with the inside/around modifiers work with non-bracket types such as quotes. so a ci[ or di( don’t work, but a ci’ or di" does.

As far as esc key rebinding, I rebind my capslock key to esc using my OS or keyboard software then set up a macro somewhere else to toggle capslock in case it gets toggled on somehow.

3 Likes

j and k working like pressing up or down arrow would make the vim mode nicer to use.

7 Likes

I agree with you, but it should likely be a setting. I think what you are describing is gj and gk. This moves straight up and down even when words are wrapping. This is default Vim behaviour.

It will be ideal when we can use a .vimrc to set things specifically. Because I do map gj to j and gk to k. I almost never find the default j and k movement to be useful or intuitive.

5 Likes