0

Goal: map <localleader>n to open "$(git rev-parse --show-toplevel)/notes.md"

I know how to do mappings, and the above git command works fine on the command line. Marrying the two together in vim has been surprisingly hard.

I tried running vim commands like this: :e system("$(git rev-parse --show-toplevel)/notes.md"), but that just opens a file called "system(".

I'll take a vimscript solution, though a lua solution is slightly more preferable.

romainl
  • 186,200
  • 21
  • 280
  • 313

1 Answers1

0

This line in my lua init file works. Backticks are the secret sauce:

vim.api.nvim_set_keymap(
  'n',
  '<localleader>n',
  ':e `git rev-parse --show-toplevel`/notes.md<CR>',
  { noremap = true, silent = true }
)