Vim autocmd read .vim file

186 Views Asked by At

I put the SyntaxAttr.vim file in the ~/.vim/autoload folder.

I want to use autocmd command to set the autoload event.

How should I do it.

Autoload the SyntaxAttr.vim.

1

There are 1 best solutions below

0
romainl On

Assuming this is the SyntaxAttr.vim in question, the author of that script seems to be a little confused about the meaning of the word "autoloading" in the Vim context and about the purpose of the autoload directory (or "autoloading" didn't exist in its current form back in 2002).

For background, how so-called "autoloading" works in Vim is introduced in section 52 of the user manual, :help 52.2 and further explained under :help autoload.

Now, you basically have two options:…

  • Keep the file in autoload/ but edit it and use it as described in the help sections above:

    " in autoload/SyntaxAttr.vim
    function! SyntaxAttr#SyntaxAttr()
    [...]
    
    " call that function manually
    :call SyntaxAttr#SyntaxAttr()
    
    " in your vimrc
    " use it in a custom command
    command! SA call SyntaxAttr#SyntaxAttr()
    
    " or in a mapping
    nnoremap <key> <Cmd>call SyntaxAttr#SyntaxAttr()<CR>
    
  • Or move the file to where it belongs, plugin/, and forget all about that weird notion of "autoloading":

    " call that function manually
    :call SyntaxAttr()
    
    " in your vimrc
    " use it in a custom command
    command! SA call SyntaxAttr()
    
    " or in a mapping
    nnoremap <key> <Cmd>call SyntaxAttr()<CR>