Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add keyword in a vim modeline

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?

like image 485
wener Avatar asked Apr 29 '26 21:04

wener


1 Answers

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.

like image 150
Ingo Karkat Avatar answered May 02 '26 10:05

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!