C.G.Senthilkumar. wrote:

Hi,

I use the following autocmd in my ~/.vimrc to load a source file with my
personal vim mappings while editing a tex file:

autocmd FileType tex source ~/Dot.vilatexrc

This works fine. However, the mappings continue to exist even after I
open a different filetype without restarting vim. Is there an "unsource"
command? If yes, how do I tell vim to do that each time I open another
filetype.

I have to add that, the appropriate syntax plugins and indent files are
loaded for the new filetype. So, I'm happy with that.

Any pointers will help.

Thanks in advance.
Senthil.

there is no "unsource" command, but you can build your script so as to avoid unwanted side-effects:

- use :map <buffer>
        not plain :map
similarly for map!, imap, cnoremap, etc.

- use :setlocal
        not plain :set

- if you need to set a global option for the duration of your script, save it on entry and restore it on exit, e.g.

        :let save_cpo = &cpo
        :set cpo&vim
        ...
        :let &cpo = save_cpo
        :unlet save_cpo

etc.

Note that a script which is only to be sourced at the FileType autocommand for tex files can be called

        (on Windows)
                ~/vimfiles/after/ftplugin/tex.vim

        (on Unix/Linux)
                ~/.vim/after/ftplugin/tex.vim

It will then run immediately after $VIMRUNTIME/ftplugin/tex.vim without the need for you to set up an autocommand. The caveats about ":map <buffer>" and ":setlocal" still apply.

If your script has a different name, and you don't want to rename it, you can simply source it from a script with the above name; or if your system supports soft links, you can link it from ~/.vim/after/ftplugin/tex/ i.e., you can set it up with (e.g.) the following shell commands (which are shown for Unix):

        mkdir -p ~/.vim/after/ftplugin/tex
        cd ~/.vim/after/ftplugin/tex
        ln -sv ~/Dot.vilatexrc vilatex.vim

At the FileType autocommand event for tex files, Vim will lookup (among others) scripts named ~/.vim/after/ftplugin/tex/*.vim : it will find ~/.vim/after/ftplugin/tex/vilatex.vim, which is a soft link pointing to ~/Dot.vilatexrc, and source the latter.

see ":help ftplugin-name"


Best regards,
Tony.

Reply via email to