2

I am trying to figure out how to open a specific vimwiki diary on opening vim. With one wiki I use an alias like alias todo='vim -c VimwikiDiaryIndex' which works perfectly.

But now I want an additional diary wiki for another set of notes. I already added the path and can change the diary inside of vim with 2<Leader>wi.

But I don't know how to combine it with my alias commands. (Something like -c 2VimwikiDiaryIndex does not work.

Does someone know how I could get it done?

1

I'm guessing here but it seems you are trying to run normal mode mappings in batch mode (IOW, vim -c <cmd>). Your 2wi ... I'm assuming that refers to [count]<Leader>wi, a VimWiki mapped command in the docs...?

To run such mappings you need to use the norm command (:h :norm).

For example, vim -c 'norm 2\wi' if your Leader key is the default \ (backslash).

BTW, if you want to run multiple commands using this method just use a separate -c for each. Example:

vim -c 'norm 2\wi' -c 'wq'
  • 1
    You need to.use :normal and not :normal! here, since :normal! doesn't expand mappings. From :help :normal: "If the [!] is given, mappings will not be used." Otherwise, answer looks good. – filbranden Aug 9 at 13:53
  • 1
    Yeah, I know and that's how I tested it: vim -c 'e /tmp/b' -c 'norm G /1' -c 'wq'. Lord knows why in between there and here I decided subconsciously to add some bangs :P – B Layer Aug 9 at 14:00
  • 1
    @filbranden Thanks for the heads up, btw. – B Layer Aug 9 at 14:10
  • 1
    Working as hoped. Thanks. @fillbranden: also thanks for highlighting the code parts of my answer. Could not find the option while writing on my smartphone . – Abayo Aug 9 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.