DEV Community

Ez Pz Developement
Ez Pz Developement

Posted on • Originally published at abderrahmanems.Medium on

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

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

In the previous post, i discussed how to structure our vim plugin, and how we can add the beautiful syntax highlight feature.

In this short post, i will explain how to add a simple auto-complete in addition to indentation, if you want to see a full example of a working vim extension for a new programming language, please check this GitHub repository

Indentation

So first we need to create a new file in ftplugin directory, if you want to know more about autoload and other vim extension folders make sure to check the first part of this blog post here

The name of the new file is iop.vim, we will show a short example of how we handled indentation in our extension, you can check the full file here

:inoremap { {<CR><tab><CR><bs><bs><bs><bs>}<up><tab>
Enter fullscreen mode Exit fullscreen mode

Essentially, we are telling our IDE that if a user opens a bracket and then hits enter, and of course, when we press enter, we will jump to a new line with this command above the cursor will not begin at the beginning of the line but will left some space behind, the space here is represented by the .

In our case, we defined the space in the fifth line of our file as you can see below

set tabstop=4
Enter fullscreen mode Exit fullscreen mode

Autocomplete

It is time to discuss autocomplete, so we can end this blog post.

You will need to create two new folders text and autoload in the text folder we will put all the possible worlds in our new programming language, in our case we created 4 files, one for decorators, another one for types, values, and iop.text file is for identifiers.

These four files are imported in autoload/iopcomplete.vim file, this last-mentioned file contains the autocomplete logic you can check the full file here at this link .

This was just a general description of what we did to create a new simple vim extension, for this new programming language, you can understand more by reading the code in theGithub repository.

Top comments (0)