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?

2 Answers 2

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'
4
  • 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
    Commented Aug 9, 2019 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
    Commented Aug 9, 2019 at 14:00
  • 1
    @filbranden Thanks for the heads up, btw.
    – B Layer
    Commented Aug 9, 2019 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
    Commented Aug 9, 2019 at 14:26
0

Add a function like this to you ~/.bashrc:

function vimwikidiary() {
  vim -c "VimwikiIndex $1" -c VimwikiDiaryIndex
}

If you run with no arguments of with argument 1, this will open the diary index of the first wiki:

$ vimwikidiary
$ vimwikidiary 1

If you run with argument 2, this will open the diary index of your second wiki:

$ vimwikidiary 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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