VIM Mode - Quality of Life Improvements

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.

6 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.

4 Likes

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.

7 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