Wednesday, October 21, 2015

How to run a vim plugin function from vimrc?

A plugin defines a function named HLMarks():

hi Marks term=reverse ctermfg=0 ctermbg=40 guibg=Grey40

function! HLMarks(group)
call clearmatches()
let index = char2nr('a')
while index < char2nr('z')
call matchadd( a:group, '\%'.line( "'".nr2char(index)).'l')
let index = index + 1
endwhile
endfunction

I want the HLMarks() function to run automatically every time vim opens a file.
The function works when I call it manually:

:call HLMarks("Marks")

I added these two lines to the end of my vimrc:

runtime plugin/markHL.vim
HLMarks("Marks")

which got this error:

E492: Not an editor command: HLMarks("Marks")

The first answer on http://vi.stackexchange.com/questions/2791/how-to-design-a-command-in-a-plugin-that-can-be-called-from-vimrc has a similar solution, but I couldn't get it to work.

How to automatically call the HLMarks("Marks") function when a file is opened?

The plugin's markHL.vim file is in my ~/.vim/plugin/ directory.

The ":function" command lists:

function HLMarks(group)

The plugin is described on http://www.vim.org/scripts/script.php?script_id=3394
and down loaded from http://www.vim.org/scripts/download_script.php?src_id=21611

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: