llinfeng
llinfeng

Reputation: 1395

Execute `<Plug>` map for Vim through terminal/command-line, as startup arguments

I am using vimwiki, a plugin for Vim, on a daily basis; and I am wondering if I can trigger its <Plug> mapping "<Plug>VimwikiMakeDiaryNote" through terminal/command-line arguments? I have found the particular command is defined as follows:

command! -count=1 VimwikiMakeDiaryNote
  \ call vimwiki#diary#make_note(v:count1)

The <Plug> mapping is defined as:

if !hasmapto('<Plug>VimwikiMakeDiaryNote')
 exe 'nmap <silent><unique> '.g:vimwiki_map_prefix.'<Leader>w <Plug>VimwikiMakeDiaryNote'
endif
nnoremap <unique><script> <Plug>VimwikiMakeDiaryNote :VimwikiMakeDiaryNote<CR>

Is there a way to trigger the command/mapping VimwikiMakeDiaryNote through terminal/command-line, by passing something as arguments for Vim?

Upvotes: 1

Views: 579

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172570

As the <Plug>-mapping simply invokes the eponymous command, it's easiest to invoke the command directly. You can execute arbitrary Ex commands with the -c {command} or +{command} option:

$ vim +VimwikiMakeDiaryNote

Adoption on Windows & Linux OS

On Windows: use AutoHotKey

Press Win+i shall either start Gvim, or loop through all existing instances of Gvim.

#i::
IfWinExist ahk_class Vim
    groupactivate, VIM, r
else
    run C:\Vim\vim80\gvim.exe, +VimwikiMakeDiaryNote, max
return
+#i:: run C:\Vim\vim80\gvim.exe +VimwikiMakeDiaryNote, , max

On Linux

Added the following entry to ~/.bashrc

alias v='vim +VimwikiMakeDiaryNote'

Upvotes: 3

Ruslan Osmanov
Ruslan Osmanov

Reputation: 21492

Perhaps, the easiest way is to test an environment variable, e.g.:

if !empty($VIM_WIKI)
  " Your mappings...
endif

The mappings will be applied, if VIM_WIKI environment variable is not empty:

VIM_WIKI=1 vim file

Upvotes: 0

Related Questions