Reputation: 3172
I am using vim for a lot of languages and I am hoping to improve the ctrl + p/n
autocomplete. When I am going to work with a specific one I load a file in the buffer containing the substet of language specific functions I am using like so:
:badd perl.txt
This loads the functions inside that file to the auto-complete buffer
I have one .txt
file for each language I am using. I wish to automate this process by having a particular buffer loaded depending on the file type. I tried searching but cloudn't find a good answer. The only lead I have is that I might need to use filetype plugins
thought not sure how. Bonus points (though not important) if the solution is just in the rc file (since it will be easy to set up new work places that way)
One possible solution:
autocmd BufNewFile,BufRead *`<extention>` badd `<dir to file>`
Example:
autocmd BufNewFile,BufRead *pl badd /home/vim_autocomplete/perl.txt
Upvotes: 3
Views: 225
Reputation: 5112
To answer the question you asked, I think that
:au FileType * badd path/to/<amatch>.txt
(untested) will work. Instead of using :badd
, I would modify the 'complete'
option:
:au FileType * setl complete+=k/path/to/<amatch>.txt
Either way, you can wrap the command in a test:
:au FileType * if filereadable("path/to/<amatch>.txt") | ... | endif
(equally untested). Of course, if you want a single autocommand, then (whichever approach you use) you will have to name the files after the file types.
:help :au
:help FileType
:help <amatch>
:help 'complete'
Upvotes: 4