Cookie Consent by Free Privacy Policy Generator 📌 Create A Vim Plugin For Your Next Programming Language, Structure, and syntax highlight.


✅ Create A Vim Plugin For Your Next Programming Language, Structure, and syntax highlight.


💡 Newskategorie: Programmierung
🔗 Quelle: dev.to

Create A Vim Plugin For Your Next Programming Language, Structure, and syntax highlight.

Vim is a text-based editor, opensource, it is also an improved version of the old vi UNIX, Vim has so many features including multi-level undo, syntax highlighting, command line history, on-line help, spell checking, filename completion, block operations, script language, etc.

If we want to talk about compatibility, Vim runs under MS-Windows (XP, Vista, 7, 8, 10), macOS, Haiku, VMS, and almost every OS based on UNIX.

In today's post, I would like to show you how to write your own vim extension for a new programming language, I wrote this plugin with the help of my two coworkers Imen and Djamel.

Introduction

First, let me introduce you to IOP (Intersec Object Packer) it is a method to serialize data in different communication protocols, inspired by Google Protocol Buffers, IOP syntax looks like D language syntax, and all of this is according to IOP official documentation.

The Structure of a Vim Plugin

When we start working on our extension, we will create a root folder under the name vim-iop, which is exactly what we picked as a name for our vim extension.

This directory will contain three other important folders which are :

  • autoload: is a technique for blocking the loading of your plugin’s code until it’s required, in our case, we will implement the autocomplete feature in this folder.
  • ftdetect: or file type detection, has a clear purpose to figure out what file type a given file is.
  • ftplugin: contains scripts that run automatically when vim detect a file opened or created by a user, in our case this file will contain the logic to implement indentation.
  • scripts: contains a script that implements syntax highlight.

Detect File Type

In this section, we add the code to set file type for IOP files, but first, our root folder vim-iop must look like this :

vim-iop
------- ftplugin
------- ftdetect
------- syntax
------- autoload

In this part we need to create a new file ftdetect/iop.vim, add this code below to it:

" ftdetect/iop.vim
autocmd BufNewFile,BufRead *.iop setfiletype iop

Syntax Highlight

In this section, we will write some vim script in addition to some regex, so we can add the syntax highlight feature to our Vim extension.

Before we can start coding i want to mention that IOP has Basics types which are : int, uint, long, ulong, byte, ubyte ... and more, plus four complex types struct, class, union, enum , if you want to learn more about this types make sure to check this link.

So for the code below, we need add the logic to highlight the IOP types mentioned in this part of IOP documentation.

"syntax/iop.vim

**_syntax keyword_ iopComplexType** class enum union struct module **nextgroup** =iopComlexTypeName **skipwhite**
 **_syntax keyword_ iopBasicTypes** int uint long ulong xml 
**_syntax keyword_ iopBasicTypes** byte ubyte short ushort void 
**_sytanx keyword_ iopBasicTypes** bool double string bytes

" complex types name
**_syntax match iopComlexTypeName_**" **\w\+**" contained

as you can see we have iopComplexType , iopBasicTypes both of these variables contain the different complex and basic types of IOP, we also want to tell our extension that each complex type is followed by a name and that white space should be ignored, after this, we need to tell our vim extension to highlight this types by adding the code below in the bottom of syntax/iop.vim.

"syntax/iop.vim
**_highlight link_**  **iopComplexType** Keyword
**_highlight link_ iopBasicTypes** Type

in the end and after adding this extension to our vim ide, we will see something like this.

IOP syntax contains decorators also, we are going to write some regular expressions in order to highlight this, so just add the code below to our syntax/iop.vim file.

"syntax/iop.vim

syntax match iopDecorator /^ **\s*** @/ nextgroup=iopDecoratorFunction
syntax match iopDecoratorFunction contained / **\h** [a-zA-Z0-9_.]*/

In the first line of the code above we are telling our vim extension that this decorator can start with a zero or multiple white spaces followed by an “@” ( /^ \s *@/) , and the nextgroup keyword means that after “@” there is a name of this decorator, the name of this decorator can contain all alphabet letters whether it is upper or lower case, this decorator name can also contain numbers and the two special characters “_ “ and “.”.

After telling our vim extension to highlight the decorators.

"syntax/iop.vim

highlight link iopDecoratorFunction Function

This is an example of what we will see in our vim IDE.

if you want the complete implementation of vim-iop syntax highlight make sure to check this link.

That's it for now, in the next post, i will show you how to add autocomplete and indentation.

References:

...

✅ Create A Vim Plugin For Your Next Programming Language, Structure, and syntax highlight.


📈 91.79 Punkte

✅ Create A Vim Plugin For Your Next Programming Language, Indentation and Autocomplete


📈 50.21 Punkte

✅ CVE-2022-2042 | vim up to 8.1 vim/vim use after free


📈 35.72 Punkte

✅ CVE-2022-1720 | vim prior 8.2.4956 vim/vim grab_file_name buffer overflow


📈 35.72 Punkte

✅ CVE-2022-2946 | vim prior 9.0.0245 vim/vim use after free


📈 35.72 Punkte

✅ Vim prank: alias vim='vim -y'


📈 35.72 Punkte

✅ An Introduction to the Go Programming Language: Setup, Syntax, and Basic Concepts


📈 33.09 Punkte

✅ Why Vim Is More than Just an Editor – Vim Language, Motions, and Modes Explained


📈 32.96 Punkte

✅ Next.js Codebase Analysis <> create-next-app <> Folder Structure


📈 32.06 Punkte

✅ Batch File Syntax: Understanding and Mastering the Syntax for Batch Scripting


📈 31.51 Punkte

✅ Vyper Beginner's tutorial: Syntax and Structure.


📈 30.35 Punkte

✅ JavaScript Basics: Understanding Syntax and Structure


📈 30.35 Punkte

✅ GNU/Nano looks awesome with syntax highlight and interface color scheme!


📈 29.26 Punkte

✅ Highlight Your Terminal: a tools design to highlight information on output of terminal


📈 28.6 Punkte

✅ Can you use vim for any programming language? Is it common to use it for java or python?


📈 28.49 Punkte

✅ vim-plug: minimalist vim plugin manager


📈 28.44 Punkte

✅ Code/Syntax Highlighting Using highlight.js - Displaying Code on Website/Blogger with jsDelivr CDN


📈 27.75 Punkte

✅ Structure is Structure


📈 27.67 Punkte

✅ C# - Flatter structure vs Nested structure


📈 27.67 Punkte

✅ #rC3-ChaosZone - All Programming Language Suck? Just Build Your Own! – Language-Oriented Programmi


📈 27.33 Punkte

✅ #rC3-ChaosZone - All Programming Language Suck? Just Build Your Own! – Language-Oriented Programmi


📈 27.33 Punkte

✅ Customizing Vim: Advanced syntax highlighting techniques


📈 26.91 Punkte

✅ Meet LMQL: An Open Source Programming Language and Platform for Large Language Model (LLM) Interaction


📈 25.73 Punkte

✅ Go Programming Language: A Comprehensive Introduction and History of Google’s Revolutionary Language


📈 25.73 Punkte

✅ Learn Programming: What Programming Language Should I Learn First?


📈 25.52 Punkte

✅ nnn.vim: Fast and featureful file manager in vim/neovim


📈 25.32 Punkte

✅ Next.js Codebase Analysis <> create-next-app <> Create a local copy


📈 24.94 Punkte

✅ How to Highlight the Current Line in Vim


📈 24.65 Punkte

✅ Programming Solutions for Graph and Data Structure Problems With Implementation Examples (Word Dictionary)


📈 24.29 Punkte











matomo

Datei nicht gefunden!