Modding system Source code syntax highlighter for the Vim editor
Posted: Mon Sep 01, 2025 7:32 pm UTC

You can see other images explaining the feature in the post on the TW's forum.
Overview
This highlighter provides your Vim text editor a syntax highlighting feature for (not the compiled *.txt but) the source code of Mount&Blade (M&B) and Mount&Blade:Warband (M&B Warband) modding system. You modders can easily identify the objects in your code; can-fail operations, try-blocks, registers, variables, slots, etc.
Customization is easy: most how to change are intuitive when you look inside the file, and vim's help feature (:h) has more information if you need it.
Requirements
- Vim editor
(I tested on vim7.4 and vim9.1.)
If you don't have it or you want to migrate to the newest version, download it from the official site; https://www.vim.org/download.php . It should be safe enough to download non-signed zip version for personal/hobby use, e.g. gvim_9.1.xxxx_x64.zip for your 64 bit Windows. No installation such as registering in the Windows registry is required.
Note: I've not test this on neovim. Probably Vim editor should be enough for your Warband modding life. It's not too late to switch to neovim till once you've found specific issues with your vim customizations. If already you are a neovim user, migrate this highlighter for it.
Before install this highlighter, configure vim's syntax highlighting mode to be turned on automatically regardless of file types. For that, use the gvimrc file. When you open a python source file (*.py), if your vim color the some words or strings, the comfiguring is already done.
If your vim doesn't color *.py file, find gvimrc_example.vim in the vim install-directory, according to it, copy and rename it to _gvimrc and place it to your $VIM folder. The $VIM here may not be defined as an environment variable. It means your install-directory of vim. E.g. if your gvim.exe is c:\foo\vim\vim91\gvim.exe, then $VIM is c:\foo\vim. Place your _gvimrc in the directory like c:\foo\vim\_gvimrc. Check syntax on command is in it.
License
For this version, use, change, redistribute freely without notice me (the author). However, this may not be the case with newer versions.
Disclaimer
- Please use at your own risk. Regardless of whether there are any bugs in the files I made or not, I am not responsible for any damage, loss, eye-injury, brain-injury you (and people who used your inherited distribution) may incur as a result of using it.
- I won't always respond to your suggested changes, but I'm open to considering them. However, I won't respond to complaints about the coloring being difficult to read on a particular background color. I'd like you to customize those cases on an individual basis.
https://gitlab.com/Earendil_Ardamire/header_operations
From the header_operations expanded v.1.0.3 posted to the site above on about Nov 21 021, I used a Python list named can_fail_operations included. This highliter colors operations based on whether they are included in that list.
-----------------------------------------------------------------------------------
Download
Download the highlighter for vim from: Note: I may revise it without notice, but I'll always try to increment the version number.
-----------------------------------------------------------------------------------
How to install
This file set contains two mbmodsrc.vim files that have the identical name. One for the file type detection, one for syntax highlighting. Place each in the valid folder. To distinguish them, read each file. The shorter (with a few lines) is for the detection.
- Put a file for the file type detection into the directory;
Code: Select all
$VIMRUNTIME\ftdetect\mbmodsrc.vim - Put a file for the syntax highlighting into the directory;
Code: Select all
$VIMRUNTIME\syntax\mbmodsrc.vim
What the file-type-detection file does
- It activates the sybtax highlighting file when you opened module_*.py or header_*.py .
- It adds the menu path [Syntax]-[M]-[MBmodSrc] to your vim regardless of the file type you start editing. (The number like 50.80.xxx in the file means the path in the menu. To check the current menu structure, type :menu)
Alternatively, you can type a command below.
:so $VIMRUNTIME/syntax/mbmodsrc.vim
You can easily play back it from the history by typing :so (or only :s or only : if you recently use the command) and upper arrow key (once or neccesary times).
Customization
You mayn't like the color scheme that this set provides? If so, just customize it freely.
- To change the foreground/background color, search for the corresponding hi command.
- To change the rule of the syntax passed to hi command, understand the each parameters like keyword, match, contained, contains, and regular expression to specify for the "sy match" case.
- To check your current highlight settings while editing, type below when in command mode.
:hi - Use other existing syntax files in the syntax folder of vim as reference.
Try the help feature of the vim editor for detail, e.g. type commands below and search words using / . The window will splited for the help. You can end the help pane by typing :q
:h sy
:h syn-keyword
:h syn-contains
:h syn-contained
:h hi
:h ftdetect
Note
- This highlighter is not for the *.txt of the pseudo-compiled output but for the source files (*.py) of the M&B / M&B Warband modding system.
- This highlighter does not guarantee to be available for all possible background color you use. I tested for two color schemes "morning" (relatively brighter background) and "blue" (relatively darker).
- Color perception varies from user to user, and colors may appear different depending on the monitor screen and adjustment level. so, there is no perfect combination. Please customize it to suit your eyes and environment.
- This does not cover all of developers' needs. Someone may need to highlight the Starting dialog-state (the 2nd parameter) and the Ending dialog-state (the 5th parameter) in the module_dialogs.py. If that's your case, add your code for the specific file to the highlighter file under the syntax folder like:
Code: Select all
if expand('%:t') == "module_dialogs.py" " Write your code here. endif
If you are not familiar to any vi-like text editor, then search game-like free online tutorial sites (No need to make account or progress to paid level). Such sites will teach you from the usage of cursor using h, j, k, l key. There are also sites that will measure how quickly you can move the cursor to a specified position with the fewest keystrokes. It will help you understand one of the greatest benefits of vim.
To learn the vim specification for details, read the tutorial of vim itself and use help command. Start gvim.exe, hit Esc key once, and type commands like below;
:h tutor
:h
The file of the tutor for vim7.4 exists in C:\....\vim74\vim74\tutor\, for vim9.1, it's C:\....\vim91\vim91\tutor\. Find the file(s) that has your language code as its suffix (e.g. tutor.de and tutor.de.utf-8 are German). Open an empty vim and drag the file to it. Adjust setting of encoding if you have strange characters. (To check currect settings, type :set all )
Once you realize the power of a vi-like editor, you will probably want to replace your command line environment with a Unix-like and vi-like one to minimize keystrokes, to use h, j, k, l, /, n, cw, dw, i, etc. for in-line command editing, to make shell/sed/awk scripts for the build/translation, and to improve the quality of life for modding and translation drastically. if so, then search unix-like environments on Windows; e.g. Cygwin. (But a completely independent environment from Windows file system is not convenient.)