How to Enable Obsidian Vimrc Support
As a Vim user, I try to enable Vim mode wherever possible to improve my productivity. Obsidian is no different. Now that I am trying to separate writing from editing, I have started using obsidian even more. So it got me thinking, how can I synchronize my obsidian keymappings with my vim keybindings even more? 🤔
Turns out there is a plugin for that 🎉. Just install obsidian-vimrc-support and create a .obsidian.vimrc file at the root of your project and you’re good to go. We can just configure keybindings from that file like we do with our vim/neovim.
Well, except for some edge cases.
Edge Cases to be careful about
Vim wouldn’t be Vim if things just worked out of the box and we wouldn’t be Vim users if we gave up just because things are not working.
Here are the things I did (without asking too many questions) to make things work:
- I tried naming it
obsidian.vimrcwithout the dot in the front, but it didn’t work. So name it.obsidian.vimrc. - I wanted to use
<Space>as theleaderkey butmapleaderdoesn’t work. So I useddirectly in keybindings instead of <leader>.- Make sure to
**unmap** <Space>first or it won’t work in keybindings.
- Make sure to
- Due to a bug,
nmap <key> <cmd>works only when<cmd>is a single word 🤦♂. You get around it by first mapping the<cmd>against aexmapand then using theexmapwithnmap. See below.
exmap anyNameYouWant obcommand app:go-back
nmap <C-o> :anyNameYouWant
**obcommand**stands for obsidian commands. If you type:obcommandon obsidian, it prints all the possibleobcommandin the console log (pressCtrl + Shift + i). You can also find it here: obcommand list.- I couldn’t make
<Shift>work together with<Ctrl>for some reason. - To bind a particular key combination ensure it’s not already bound to something else on Obsidian. Find them in settings and unbind them from there first.
My basic configuration for Obsidian Vimrc
I have started with a few basic configurations. Key binds for:
- Navigating back and forward between files using
<C-o>and<C-i>. - Searching files using
<Space>sf - Toggling left sidebar with
<C-n>
Here is how it looks. It’s not much but now that I have the basic setup, it will continue growing. In the meantime, hopefully, the plugin will be able to sort out its quirks.
" set leader
unmap <Space>
" Have j and k navigate visual lines rather than logical ones
nmap j gj
nmap k gk
" I like using H and L for beginning/end of line
nmap H ^
nmap L $
" Yank to system clipboard
set clipboard=unnamed
" Go back and forward with Ctrl+O and Ctrl+I
" (make sure to remove default Obsidian shortcuts for these to work)
exmap back obcommand app:go-back
nmap <C-o> :back
exmap forward obcommand app:go-forward
nmap <C-i> :forward
" Search file
exmap searchFile obcommand global-search:open
nmap <Space>sf :searchFile
" Toggle left side bar
exmap toggleLeftSideBar obcommand app:toggle-left-sidebar
exmap revealFile obcommand file-explorer:reveal-active-file
nmap <C-n> :toggleLeftSideBar
nmap <Space>gf :revealFile