Configuring vim

apt-get install vim

vim is called 编辑器之神arrow-up-right. You will use vim for coding in all PAs and Labs, as well as editing other files. Maybe some of you prefer to other editors requiring GUI environment (such Visual Studio). However, you can not use them in some situations, especially when you are accessing a physically remote server:

  • the remote server does not have GUI installed, or

  • the network condition is so bad that you can not use any GUI tools.

Under these situations, vim is still a good choice. If you prefer to emacs, you can download and install emacs from network mirrors.

Learning vim

You are going to be asked to modify a file using vim. For most of you, this is the first time to use vim. The operations in vim are quite different from other editors you have ever used. To learn vim, you need a tutorial. There are two ways to get tutorials:

  • Issue the vimtutor command in terminal. This will launch a tutorial for vim.

    This way is recommended, since you can read the tutorial and practice at the same time.

  • Search the Internet with keyword "vim 教程", and you will find a lot of tutorials about vim.

    Choose some of them to read, meanwhile you can practice with the a temporary file by

    vim test

PRACTICE IS VERY IMPORTANT. You can not learn anything by only reading the tutorials.

Here are some games to help you master some basic operations in vim. Have fun!

Enabling syntax highlight

vim provides more improvements comparing with vi. But these improvements are disabled by default. Therefore, you should enable them first.

We take syntax highlight as an example to illustrate how to enable the features of vim. To do this, you should modify the vim configuration file. The file is called vimrc, and it is located under /etc/vim directory. We first make a copy of it to the home directory by cp command:

And switch to the home directory if you are not under it yet:

If you use ls to list files, you will not see the .vimrc you just copied. This is because a file whose name starts with a . is a hidden file in GNU/Linux. To show hidden files, use ls with -a option:

Then open .vimrc using vim:

After you learn some basic operations in vim (such as moving, inserting text, deleting text), you can try to modify the .vimrc file as following:

We present the modification with GNU diff formatarrow-up-right. Lines starting with + are to be inserted. Lines starting with - are to be deleted. Other lines keep unchanged. If you do not understand the diff format, please search the Internet for more information.

After you are done, you should save your modification. Exit vim and open the vimrc file again, you should see the syntax highlight feature is enabled.

Enabling more vim features

Modify the .vimrc file mentioned above as the following:

You can append the following content at the end of the .vimrc file to enable more features. Note that contents after a double quotation mark " are comments, and you do not need to include them. Of course, you can inspect every features to determine to enable or not.

If you want to refer different or more settings for vim, please search the Internet. In addition, there are many plug-ins for vim (one of them you may prefer is ctags, which provides the ability to jump among symbol definitions in the code). They make vim more powerful. Also, please search the Internet for more information about vim plug-ins.

Last updated