How to run a vim plugin function from vimrc?
Asked Answered
B

2

8

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)
Breed answered 21/10, 2015 at 1:51 Comment(0)
B
4

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

Breed answered 22/10, 2015 at 13:29 Comment(0)
T
1

If you define the function in .vimrc then:

function! yourFunc()
    " ...
endfunction

call yourFunc()

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

Tong answered 2/8, 2021 at 13:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.