VIM Mode - Quality of Life Improvements

Would like to second the point about Neovim; I don’t think that we even need to necessarily embed the editor, Obsidian can probably do it in the same fashion that the VSCode neovim extension does it; by just using nvim as a “backend”: https://github.com/asvetliakov/vscode-neovim#how-it-works

I also commented on this thread about adding Neovim as a “plugin”, however I think we’d get 90% of “I wish Obsidian’s Vim mode could do X” requests by just doing it the way the VSCode extension does it and replacing vim keybindings with it entirely.

8 Likes

Steps to reproduce

(with vim mode enabled)

  1. make a file with the following text:
# abcdef
## abcdefg
text text text text text text
text text text text text text
text text text text text text.
  1. fold the H2 heading (abcdefg)
  2. place cursor on g in H2 heading
  3. go up one line (press K)
  4. go down one line (press J)

Expected result

The cursor should return to the char g or atleast return somewhere on the heading

Actual result

The fold is opened and the cursor jumps to the end of the last line. In the above example it jumps to the fullstop

Environment

  • Operating system: Ubuntu 20.04
  • Obsidian version: 8.0.0

Additional information

This is a minor issue, but in vim mode it is common to scroll in a file using the J and K keys (like using arrow keys in non-vim mode) and random folds opening as you scroll and jumping of the cursor interrupts the flow of editing a lot, especially if the fold has lots of text.

I suspect it might be due to the editor wanting to place the cursor at the end of the line as you scroll, but instead placing it at the end of the fold. In vim when going down from a longer line to a shorter line it jumps to the end of the line depending on where the cursor was initially, that might be whats affecting this.

This happens in a lot of random places in my files, the above example was just one i was able to reproduce. I also was not able to reproduce this in normal (non vim) mode.

1 Like

Copy doesn’t work when using the keyboard shortcuts. In both Insert and Normal mode.
Right clicking and then selecting Copy does work.

3 Likes

I wouldn’t consider this a bug. This is always the case for IDEs with vim keybindings and you usually override what Ctrl+C does (see JetBrains, Atom, etc).

See also: VIM Mode - Quality of Life Improvements

Well then Ctrl-V shouldn’t be working either.

Yeah, maybe. You can still enter visual block mode with Ctrl+V from normal mode if you want. Either way, the ability to remap keys is the main point here.

1 Like

I completely agree.

For those who want the Ctrl+C combination to work with clipboard in Vim mode - you can temporary unmap keybinding in your current session.

Run CodeMirror.Vim.unmap('<C-c>') in console. You can do remapping similar way.

3 Likes

@mrjackphil’s great tip emphasizes the need to Support loading Vim commands from configuration (vimrc-style).
Otherwise, like he says, this is a temporary hack that needs to be repeated on every session.

2 Likes

wow @mrjackphil thank you for that tip on unmapping ctrl+c on console. It works perfectly.
Is there any way to make this into a volcano plug-in. So that in persists after restarting obsidian?
thank you!

1 Like

I believe (but I could be wrong, of course) what testing API would be available soon. I’ll adapt this workaround for it.

2 Likes

Thank you so much, I’ll keep an eye for it once the API is available. I appreciate your hard work!

1 Like

I would add that currently using standard vim navigation I can not move cursor behind the last symbol in the line.

I guess thats normal vim. You can press a to get in insert mode right from the cursor.

1 Like

thank you for the tip. I’m new in vim. However I’ve checked this in Neovim and it works as expected

1 Like

in Neovim and it works as expected

In Neovim, when in Normal Mode, do you have a block cursor, or a line cursor? I am guessing that if you have a line cursor, it would appear that the cursor is to the right of the last character.

If you have a block cursor, which is what Obsidian uses in Vim mode, then it will appear to be over top of the last character in the line. A line cursor on the other hand, shows up as between characters, so at the end of a line, it shows to the right of the last character.

Obsidian:
image

Neovim with a block cursor:
image

I’ve configured my Vim so that when I’m in Normal Mode, I see a block cursor, which more precisely tells me where I am. “I am on the last character in the line”. When I’m in Insert Mode, I see a line cursor, which more precisely tells me where text will insert. (In my opinion/experience.)

This is how Obsidian works. When you go into Insert Mode, it goes back to a line cursor. So I experience no difference in how this behaves between Obsidian and Vim.

2 Likes

ok, ok. My experience with vim is very very limited. almost nothing. I just found that weird that using mouse you may put cursor behind the last symbol however using navigation keys you are not able to do so

EDT: Despite this minor thing, I’m enjoying this tool.

best,
ilya

Oh yeah I see what you mean now. That seems to be a glitch, to me.

If you click with the mouse to the right of a line, the block cursor does move to empty space. You shouldn’t be able to do that with the mouse, either. As far as I can tell, that is actually the glitch. It works as expected (to me) with the keyboard.

If you’re like me who’s new to Obsidian and can’t write anywhere else without Vim keybindinds, my current solution is to add a shortcut to Open in Default App (which the extension .md is set to Vim).

After that, when you want to write, trigger the hotkey and write in the real Vim. I know it’s not pretty but it’s the only want I can write without typing jk over and over and over.

2 Likes

I managed to cofigure vim mode to work really nice in obsidan, I’ve taken notes on some fixes for Linux and Mac.

What is it that’s not working in your obsidian vim mode, I might be able to help.

Does holding down one of the hjkl keys not work for you?