wolfv
wolfv

Reputation: 993

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. It works when I call the function manually:

:call HLMarks("Marks")

Adding this line to the end of the plugin didn't do anything:

call HLMarks("Marks")

Calling the function from vimrc got this error:

E117: Unknown function: HLMarks

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

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

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

The ":function" command lists:

function HLMarks(group)

Upvotes: 8

Views: 9416

Answers (2)

NeoZoom.lua
NeoZoom.lua

Reputation: 2921

If you define the function in .vimrc then:

function! yourFunc()
    " ...
endfunction

call yourFunc()

simply adding the call yourFunc() after the definition will work.

Upvotes: 1

wolfv
wolfv

Reputation: 993

The solution is to add this line to vimrc:

autocmd BufReadPost * call HLMarks("Marks")

Details are at https://groups.google.com/forum/#!topic/vim_use/i2HWD_9V-28

Upvotes: 4

Related Questions