VimArea - Day 16 - line shifting
( Recently I've been busy playing Stardew Valley. Aaaand I've just lost interest after getting married and had a baby. These games are fun at the development stage, but once you get to the *realization* stage1. The tasks became dull and monotonous. Just like Minecraft, like /r/meirl )

Code indent is an important feature that should never be missed. Python even uses the indentation to replace the usage of brackets.

However, I was not satisfied by the ways that Vim handles the indent. There were mainly two things I have concerned:

1. Auto indent does not inherit the indentation from last line

There is always a war between tab and space. Personally I'd prefer tabs because it provides the flexibility of changing the tab width while needed. But Vim does not know if an existing document should use tab or space. One way to do that is to set expandtab base on the filetype detected.

But there is always a preference when you working with different people. Some people like spaces, some like tabs. From time to time I occasionally run into a situation that I need to constantly changing between tabs and spaces.

2. Vim is too smart to indent for me

Say if I have typed this snippet of code:
public void test()
{
	String a = "abcdefg"
}
Then I press Enter to make a line for more room to add a + sign to join lines together
public void test()
{
	String a = "abcdefg"
		+ "higklmno";
}
Vim does this "increment the indent level by one" feature that is usually not what I want. For me I would prefer:
// 1. Either the "symbols" are aligned properly.
public void test()
{
    String a = "abcdefg"
             + "higklmno";
}

// 2. Or just keep the old indent level. Because I like codes that are neatly patterned.
public void test()
{
	String a = "abcdefg"
	+ "higklmno"
	+ "pqrs"
	+ "tuvw"
	+ "xyz"
	;
}

Improving the indent features

Since this my impl of Vim. I would like to make it more convenient ( type as less as possible ) for casually writing demo codes on a website ( textarea ).

inheriting the indent level from the last line

This is done by trying to find indent from the last line if possible. If the last line does no exists. Use the default settings. The advantage of this is it keeps the indent preference for the existing document. If the document is indented with spaces, it keep using spaces.

This also allows me to do a neat little tricks that I could *chop* the indent level by pressing Enter in the middle of indent:

Although it is not a very useful feature, but at lease it is useful when it is used ;)

Articles in the series


Useful Links

Project home | Demo
  1. The realization of "I am just grinding for resources, so I could upgrade the tools for grinding more resouces"
Tag(s): vim BotanJS
Profile picture
斟酌 鵬兄
Sun Apr 17 2016 08:45:11 GMT+0000 (Coordinated Universal Time)
Last modified: Sun Apr 17 2016 08:48:12 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 服務被牆掉了,所以不能回覆了