Marc Weber wrote:
I want the script to automatically close function with endfunction

while with
endwhile

for with
endfor
[...]

Looks like you have ideas for omni-completion on Vim files. You may want to define 'omnifunc' in a script of one of the following names:

user-private on Windows
$HOME/vimfiles/after/ftplugin/vim.vim

user-private on Unix
$HOME/.vim/after/ftplugin/vim.vim

system-wide on any platform
$VIM/vimfiles/after/ftplugin/vim.vim

(Create the directory if it doesn't exist yet.)

You may want to wrap the function definition and the "set omnifunc=" statement inside "if exists('+omnifunc')" to avoid errors with version-6 Vim.

Then once your function is defined, type (in Insert mode) "end" (without the quotes) followed by Ctrl-X Ctrl-O and, if applicable, the word should be completed to one of "endif" "endwhile" "endfor" "endtry" or "endfunction". Hit Ctr-X Ctrl-O on a line with only zero or more spaces or tabs before the cursor, and you should get a menu of Ex-commands. And so on. The current ftplugin/vim.vim doesn't (yet) set up omni-completion, but IMHO it's a blemish -- at some future date (and you can help with it if you feel up to the task) the mechanism should become integrated within $VIMRUNTIME/ftplugin/vim.vim and described under the not-yet-existent ":help ft-vim-omni". (In the meantime, you may document what you write, by creating, for instance, a new helpfile named "$VIM/vimfiles/doc/omni.txt". Then you'll run ":helptags $VIM/vimfiles/doc" once to create (or update) a "tags" file in that directory so that from then on your "own" help will be automagically integrated with the Vim help on your system.

You may want to use as a source of inspiration the existing $VIMRUNTIME/ftplugin/c.vim, $VIMRUNTIME/ftplugin/html.vim, etc., which do define omni-completion. Don't change anything in the directory tree starting at $VIMRUNTIME, however, because any upgrade may silently change it back.

see
:help compl-omni
:help complete-functions
:help 'omnifunc'
:help ft-*-omni<Ctrl-D> or :help ft-*-omni<Tab>
:help after-directory
:help 'runtimepath'
etc.


Best regards,
Tony

Reply via email to