Hi, in case some of you also use or plan to use Obsidian and Vim (resp. vimwiki) side by side as two different viewports on the same notebase, this might be useful[^1] (the following describes solutions for macOS; maybe someone else could provide infos on how to do this on Linux or Windows):
Open note in Vim from within Obsidian
If you use Vim in iTerm, you can just create an App with Automator:[^2]
-- TerminalVim.app
-- This creates a shim Application that will enable you to open files from the Finder in vim using iTerm
-- To use this script:
-- 1. Open Automator and create a new Application
-- 2. Add the "Run Applescript" action
-- 3. Paste this script into the Run Applescript section
-- 4. Save the application as TerminalVim.app in your Applications folder
-- 5. In the Finder, right click on a file and select "Open With". In that window you can set TerminalVim as a default
on run {input, parameters}
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text ("vim " & quote & POSIX path of input & quote & "; exit")
end tell
end tell
end run
If you use Neovim, just replace “vim” with “nvim”. After following all steps, you can open a note from within Obsidian with the “Open in default app” feature (you can create a shortcut in the settings).[^3]
Open note in Obsidian from within Vim
With the URL feature of Obsidian, this is now also possible. I just added the following to my .vimrc
/ init.vim
:
" Open file in Obsidian vault
command IO execute "silent !open 'obsidian://open?vault=VAULTNAME&file=" . expand('%:r') . "'"
nnoremap <leader>io :IO<CR>
You just have to replace VAULTNAME
with the actual name of your vault. You can then press <leader>io
(for “in Obsidian”) to open the currently opened note in Vim in Obsidian. In case you use Linux, you have to replace the open
command with the equivalent command (e.g. xdg-open
).
[^1]: As a sidenote: I would recommend using the “relative paths” settings in Obisdian, if you want to use vimwiki as a second (or future fallback) edit environment, because this allows you to follow the links in vimwiki.
[^2]: Source: https://gist.github.com/charlietran/43639b0f4e0a01c7c20df8f1929b76f2
[^3]: This opens a new window in iTerm. It should be possible to open a file in a running instance of Neovim, but due to a bug in macOS I can’t test that right now. I might add this later.