为vim自定义mfix中的高亮关键词

目标

用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内容放在文末附录了。

自定义高亮的操作流程

(假设目前已经在上述自定义关键词文件所在目录)

  1. 复制.vimrc文件到HOME文件夹
 cp .vimrc  ~
  1. 创建~/.vim/syntax/目录
   mkdir ~/.vim
   mkdir ~/.vim/syntax
  1. 复制 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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值