Support loading Vim commands from configuration (vimrc-style)

thanks @Vinadon for sharing your script, could you provide some instructions for setting it up for Obsidian if possible?
also, does it work for linux manjaro?

It is not my script, I found in in the internet, but because it is codemirror, you can use it in obsidian as well. I didnt make a public plugin, because I am not sure with the rights and so on with this script.
To use it you have to

  1. create you own plugin with this template
  2. put the yank.ts in your plugin folder
  3. register it with
this.registerEvent('codemirror', (cm: CodeMirror.Editor) => {
     CodeMirror.Vim.defineOperator("yank", yankGenerator(CodeMirror.Vim.getRegisterController(), true))

somewhere in your main.ts

Honestly I dont know what the last argument stands for, I noticed no differene between true and false, but it works. EDIT: I found some info, but I guess true is the right choice.

It will throw some types error, because it cant find Vim and so on, but I guess it is just not well documentated.

To make it accessible for everybody, do you mind opening a PR to add this to the Vimrc plugin? I’d add a custom option (CodeMirror.Vim.defineOption) named clipboard to make it configurable similarly to Vim.
If you don’t get to it I’ll do it in the next few days.

1 Like

What do you mean exactly with?

I’d add a custom option (CodeMirror.Vim.defineOption) named clipboard to make it configurable similarly to Vim.

Do you want that it is configurable with the .vimrc file? What options and syntax do you have in mind?

In addition, should I ask the author of the originial script if is ok to use it?

it would be amazing @Vinadon and @esm90 to have this as part of obsidian.vimrc looking forward to it, thanks!

I was thinking to bind the yank register to the system clipboard using a set clipboard=unnamed.
IMHO those two lines you copied are too trivial to ask permission for, but it’s up to you. If you don’t feel comfortable, some time next week I’ll investigate this from scratch without using this snippet.

1 Like

I tried it myself, but I dont understand the error messages and so on. I am just not comfortable with codemirror. Happy to see what you will achieve when you find the time for it.

1 Like

You may go ahead and update, I added the support for copying to system clipboard (add set clipboard=unnamed to your vimrc), and also the promised support for vimrc comments & blank lines.

@Vinadon I eventually chose a different approach than what they did at Jupyterlab. Over there they essentially re-implemented the yank command from scratch because CM doesn’t expose it via the API. But I think that’s not so future-proof (e.g. may not work well on future versions of CM), so instead of that, I added code that monitors the CM Vim yank register and copies it to the system clipboard when a change is detected (if configured to do so).


I can confirm that it works great on linux, thanks a lot @esm90 it’s such a great time saving feature, really appreciate it!

Thank you. Yeah thats a better implementation. I didnt know you can listen to it.

Is there any way to put j k navigation in document view mode? Wildly annoying in viewing mode that you can not use VIM combinations to navigate the document. I would really appreciate your help.

Do you mean use Vim keybindings in Markdown Preview mode (e.g. for scrolling)? AFAIK the Markdown preview is an entirely different component, it’s like adding Vim bindings to a web browser (like Vimium etc.)
If that’s what you mean then it’s definitely possible for a plugin to catch these keys and make them scroll but I think this needs to be a different plugin.

1 Like

I understood. Thanks.

1 Like

Thank you so much for your effort creating the plugin.
I’m really sorry, but I’m having trouble locating/creating the vimrc file.

Can you kindly advise how I maybe able to address this issue?

Thank you!

you have to create a file called .obsidian.vimrc in your obsidian vault (in the same folder where all your obsidian notes are created)
This will be a hidden file, if you turn on the community plug in, it should read it.

That’s the long story short, if you still have trouble let us know!


I have no idea if this is technically feasible, but adding ctrl-p and crtl-n for autocomplete backwards and forwards would be wonderful.

Dear @santi,
Thank you for your kind response!
I think the part I am struggling is the more rudimentary (and novice) issue with actually creating a .obsidian.vimrc file. I don’t know how to make the file in the first place :joy:
Would there a command prompt that I run?

Thank you so much for your time and support!

1 Like

No worries @hanjae87 , it’s a hidden file which makes it confusing.

It’s a file at the same level as .obsidian (root folder with the rest of your notes)

It follows the same concepts as the .obsidian folder, but the .obsidian.vimrc is a file not a folder.

I wrote a blogpost on .obsdian so it’s not exactly the same, but it will definitely help you out

Let me know if you got any questions, since I know these things can be confusing

1 Like

Dear @santi,
Thank you for the explanation!
Unfortunately, I still can’t seem to find the .vimrc file anywhere.
I turned on the option to view hidden files as well.
Would I need to create/touch this file or is it automatically created?

The odd thing is I see the .obsidian file whether or not I have the option to view hidden files toggled on or off.

Thank you again!

1 Like

No worries, so you need to create the file. It won’t be there by default.

It has to be named .obsidian.vimrc

Let me know if it worked for you