On Thu, Oct 22, 2015 at 8:21 AM, wolfv <wolfvolpi@gmail.com> wrote:
> 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
>
If you want the function to run every time you open a file, you
shouldn't put a bare call statement to it in your vimrc (which would
try to call the function exactly once, at startup, and then no more).
What you need is an autocommand, which will run whenever a file is
open. You can set this up in your vimrc, for instance as follows:
autocmd BufReadPost * call HLMarks("Marks")
Since global plugins are sourced after the vimrc, but before opening
any buffers, this ought to take care that the function is defined
before it is called.
Best regards,
Tony.
--
--
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:
Post a Comment