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?
You can't do that directly; only (buffer-local) options can be set in modeline.
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.
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.