VimArea - Day 5 - Commands ( failed )
*Before going through this article I would like to say this is a failed attempt of the implementation. However this is a series about what I did on re-implementing Vim. So I am still going to post this article because I might be able to learn something from it later.

Reverse engineering Vim was both fun and challenging. Since I am NOT going to read the help section thoroughly. I've to try every possible commands I could figure of. Since this is the most efficient way to implement the commands that me - and perhaps most of us uses.

Then I discovered some commands that are integrative. I could chain them together to form a single action. And they could both be chained to some advanced commands!

Since the next thing I am going to implement is the -- VISUAL -- command. Let's take this as an example:

By pressing V the vim will brought me to the -- VISUAL -- mode. The integrative commands I could use here are i,t,hHjklL... most of them are cursor manipulation. But then I could also use the : command to do even more!

That moment I realize that the model of Vim is not what I'd suspected - that the commands are handled separately. The commands are mostly depends to the cursor as the point of action and thus give me the idea:

Cursor Commands

The cursor commands are the ways to manipulate the cursor position. I could use $ to go the end of the current line. L to go to the current visible end, t to have the cursor go to somewhere specific, etc. These I called the cursor commands.

Action Commands

Unlike cursor commands. These commands are record-able. I could use the u / Ctrl + r to undo / redo them. And inside this command, I could manipulate the cursor. Example of the commands are V, D, <, > etc.

Rewriting the command structure

Initially I've made the cursor commands separate. That is, if I want the cursor movement inside the action command. I would have to handle the commands inside the action command itself again.

Below is the revamped handling priority of the commands:

As you see every key I press needs to go through each layer for processing which action a user wanted to do. Currently I am quite worried about the end performance when the implementation is complete.

Control Commands

Some commands are just special that it overrides the cursor movements. But I believed there are only few of them. The only I could figure of are INSERT/ and
:, which two of them I called control commands( that would be a later topic ). I think commands that overrides the cursor movements are generally the ones that requires you to input alphabetical characters.

Composite Commands

It seems like the commands in vim are so many that it exhausted the alphabetic keys in the keyboard. Thus comes the composite commands. They are long commands that start with a prefix g.

Update - why failed ?

After a big more fiddling I figured that was the way to describe the command structure of the original Vim! So here's what I discovered:

1. By pressing the d command. The g command ( gg, gdg8... ) behaves slight differently as I expected. So the d command should ended by a cursor movement event but terminated by any other commands.
2. Some of the commands I type in -- VISUAL -- didn't terminate it the commands are not about cursor movement. ( Such as g8 ) I could also use the / command without terminating it.

So the above condition couldn't be made using the above structure. I think I should step back and handle all of them separately and after that I do the structural optimization.

Articles in the series


Useful Links

Project home | Demo

Tag(s): BotanJS vim
Profile picture
斟酌 鵬兄
Sat Mar 19 2016 17:36:07 GMT+0000 (Coordinated Universal Time)
Last modified: Sun Apr 10 2022 07:51:40 GMT+0000 (Coordinated Universal Time)
Comments
No comments here.
Do you even comment?
website: 
Not a valid website
Invalid email format
Please enter your email
*Name: 
Please enter a name
Submit
抱歉,Google Recaptcha 服務被牆掉了,所以不能回覆了