Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a vim plugin function from vimrc?

Tags:

vim-plugin

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)
like image 348
wolfv Avatar asked Oct 21 '15 01:10

wolfv


People also ask

How do I run a function in Vim?

You can always execute Vimscript by running each command in command mode (the one you prefix with : ), or by executing the file with commands using a :source command. Historically, Vim scripts have a . vim extension. Here, :so is a short version of :source , and % refers to the currently open file.

How do I use Vim plugins?

Installing a Plugin Manually Starting with Vim version 8, you can install plugins without the need for a package manager by using the default package management tool. You can place Vim plugins in the ~/. vim/pack/vendor/start/plugin_name directory. Note that the plugin_name folder name will vary from plugin to plugin.

How do I access vimrc?

In the terminal, type vi . vimrc . This will create an empty vimrc system file which you want to use. In the file, type set number , and then hit Esc on the keyboard and type in :wq .

What is vimrc file?

Settings file used by Vim, a text editing program often used by source code developers and system administrators; saves the default settings for the editor when it is opened; allows users to customize options for the editor. VIMRC files are saved in a plain text format.


1 Answers

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

like image 109
wolfv Avatar answered Sep 30 '22 13:09

wolfv