目标
用mfix GUI自带的editor打开.mfx文件的时候是有关键词高亮的。但是换个文本编辑器就没了,本文希望不用mfix GUI也能对mfix中的关键词进行高亮显示。
前提说明
本教程只是安装到vim这个编辑器上的,如果vim没有请下载。目前还没探索出如何在VS code等常用文本编辑器上使用。后续可能会补充。
mfix关键词位置
既然mfix自带的GUI能高亮,一定在某个地方定义了关键词。经过查找位于:
~/miniconda3/envs/mfix-20.4.3/share/mfix/src/tools/vim
请按照自己的mfix安装位置自行更改。
里面有四个文件,注意有一个隐藏文件(linux中以.开头的是隐藏文件)
如果看不到隐藏文件可以开启
其中readme就是官方给出的如何自定义高亮的教程,我们下面就按照这个教程操作。readme内容放在文末附录了。
自定义高亮的操作流程
(假设目前已经在上述自定义关键词文件所在目录)
- 复制.vimrc文件到HOME文件夹
cp .vimrc ~
- 创建~/.vim/syntax/目录
mkdir ~/.vim
mkdir ~/.vim/syntax
- 复制 mfix.vim文件复制到刚创建的~/.vim/syntax
cp mfix.vim ~/.vim/syntax
效果
GUI里展现的是
可见GUI中绿字的部分是成功高亮了的。
附录:readme
The files provided in this directory (/mfix/tools/vim) can be used for syntax highlight and keyword
autocompletion of mfix.dat input file.
ASSUMPTIONS:
MFIX is installed on the home directory.
Adjust all paths if this is not the case.
INSTALLATION:
1) Copy the .vimrc file to your home folder:
cp ~/mfix/tools/vim/.vimrc ~
(Please see note below if you already have a .vimrc file)
2) Create ~/.vim/syntax/ directory if it doesn't exist:
mkdir ~/.vim
mkdir ~/.vim/syntax
3) Copy the mfix.vim file to ~/.vim/syntax:
cp ~/mfix/tools/vim/mfix.vim ~/.vim/syntax
USAGE:
Syntax highlight is automatic. Known MFIX keywords and other types of text
(comments, string of characters, etc) will be highlighted.
Keyword auto-completion: In INSERT mode, type the firts letter(s) of a keyword
and press "Ctrl+N" or "Ctrl+P" to trigger auto-completion and go through the
list of proposed keywords from the shown menu. Press "Enter" to validate entry.
Note: If you already have a .vimrc file
_______________________________________
Copy the following lines to you existing .vimrc file
to enable syntax highlight and keyword auto-completion:
" Syntax highlighting for mfix.dat
au BufRead,BufNewFile mfix.dat set filetype=mfix
au! Syntax mfix source ~/.vim/syntax/mfix.vim
syntax on
" Auto-completion for mfix keywords
set complete=k
set dictionary+=~/mfix/tools/vim/mfixdictionary.txt