Question

For example, my file looks like:

#! /bin/bash
verbose()
{
    [ "$VERBOSE_FLAG" == 'yes' ] && 
    {
        [ $# == 0 ] || echo $@
        return 0
    } || return 1
}

verbose display in verbose mode

# make verbose highlight as a keyword
# vim: syntax keyword Keyword verbose

Is it possible use syn in a modeline or is there any alternative way?

Was it helpful?

Solution

You can't do that directly; only (buffer-local) options can be set in modeline.

option 1

If this additional keyword is not special to a single file, but applies to a wide range of files, I'd define a custom filetype (e.g. mybash), and have that additional keyword added in ~/.vim/syntax/mybash.vim:

" mybash is a kind of shell syntax
runtime! syntax/sh.vim syntax/sh/*.vim

" Add keyword.
syntax keyword mybashKeyword verbose

To use that custom syntax, you either augment the default filetype detection rules, or include ft=mybash in the modeline.

option 2

If this is just a minor tweak for one or few files, I'd use a local vimrc plugin to add the keyword.

There are several such plugins on vim.org; I can recommend the localrc plugin, which even allows local filetype-specific configuration.

OTHER TIPS

Vim modelines are used to set various vim options (see :help modeline and :help options.txt). Since syntax highlighting is a command and not an option, it cannot be specified via a modeline. However, you can set syntax highlighting for a particular filename, file type, directory, etc. Simply use an autocommand (see :help au) to specify the file pattern you want to match and the command you want to execute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top