Wikia

Vim Tips Wiki

Tonymec/syntaxcomplete.vim

Talk0
1,613pages on
this wiki

< User:Tonymec

Revision as of 21:08, August 4, 2009 by Tonymec (Talk | contribs)

The following script implements an idea found at :help ft-syntax-omni by carrying it to its logical end, in the form of a global plugin separate fropm other scripts. To enable it for all users of your Vim installation, just paste it as $VIM/vimfiles/plugin/syntaxcomplete.vim (and create any missing directories as you go along).

The code

if exists("s:loaded_syntaxcomplete")
    finish
endif
let s:loaded_syntaxcomplete = 1

if has("autocmd") && exists("+omnifunc")
    function ToggleSyntaxComplete()
        if exists('#syntaxcomplete#Filetype')
            au! syntaxcomplete
            augroup! syntaxcomplete
        else
            augroup syntaxcomplete
	        au Filetype *
                    \ if &omnifunc == "" |
                    \ setl omnifunc=syntaxcomplete#Complete |
                    \ endif
            augroup END
        endif
    endfunction

    call ToggleSyntaxComplete()
endif

Acknowledgments

Thanks to Spiiph for an elegant improvement which has been incorporated into the above code.

See also

Comments

Please leave comments here, not on a talk page; sign them with ~~~~ and separate unrelated comments with ----. — Tonymec 19:20, 3 August 2009 (UTC)


I believe that recommending users to put this script in ~/.vim/plugin (or $HOME\vimfiles\plugin) is better than suggesting that they install it for all users. Most sysadmins should know how to do this (or be able to easily figure it out) anyway. In addition, many Linux distributions (including Debian based ones) use separate directories for system wide plugins, because they wipe the $VIM directory when updating.

Thanks for telling me: now I'll be sure never to run Debian (or Ubuntu etc.). Well, the alternative is to use "~/.vim/plugin on Unix or ~/vimfiles/plugin on Windows". Let's say I was lazy. ;-)
Well, FYI, Debian has the best Vim package I've ever seen. It correctly adds a specific directory for administrator installed scripts and plugins to 'runtimepath', and even provides a set of scripts to install and remove them. It thereby allows for easy upgrading of the core components, without interfering with custom scripts and plugins added by the sysadmin. Don't knock it 'til you try (or at least understand) it.

Other than that, I think this would be a good adition to Omni_completion. (Spiiph 21:00, 3 August 2009 (UTC))

The important part is already in the omnicompletion help, under :help ft-syntax-omni, except that it doesn't "modularize it out" of the vimrc. Hm, why not a link and/or an update of that Vim wiki tip? I'm going to ask "someone whose advice I trust" about all this user-subpages business. — Tonymec 21:18, 3 August 2009 (UTC)
Are you asking why I didn't update that tip? Because I thought you might want to do it. It's your conception, after all. :) (Spiiph 21:30, 3 August 2009 (UTC))
Oh, I may still do it, but not yet: first, I want to think some more about what to do and how. Then, when I think I know what should be done, I'll open that page's edit form. — Tonymec 21:48, 3 August 2009 (UTC)

Around Wikia's network

Random Wiki