Sunday, March 28, 2010

Re: How to define a command only available for a certain filetype.

Got it. Thanks very much Andy! ^_^

On 3月28日, 下午8时43分, Andy Wokula <anw...@yahoo.de> wrote:
> Am 28.03.2010 09:48, schrieb vfantasie:
>
> > Hi everyone!
>
> > I want to define a command only available for a certain filetype, for
> > example cpp filetype:
>
> > 1. The command is available when the current buffer is cpp filetype.
> > 2. The command is undefined if I didn't open cpp file, or the current
> > buffer is not cpp filetype.
> > Because I want this command invisiable if it not wanted.
> > 3. The suffix of C++ file can be .cc .cPP .CPP .Cpp .h ..... The
> > command should be available all kind of cpp files.
>
> > How to do this? Many thanks in advance.
>
> Edit your
> after/ftplugin/cpp.vim
> script [1] and add a command with a -buffer modifier:
> :command! -buffer ... CmdName ...
> :h :com
>
> Then the command will only be available local to the buffer.
> (in case you wonder: there is no "local to the filetype" concept).
>
> "cpp" in "cpp.vim" is the name of the filetype that Vim detects,
> others may know better what will apply for your case.
>
> [1] e.g. ~/.vim/after/ftplugin/cpp.vim (check your 'rtp' setting), you
> may have to create the "after" and "ftplugin" directories first.
>
> --
> Andy

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

No comments:

Post a Comment