Configuring Vim
It's god of editor.
Last updated
Was this helpful?
It's god of editor.
Last updated
Was this helpful?
vim
is called . You may use vim
for coding or editing some files directly in OS lab environment. 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. Another reason to choose vim
is that, vim
can greatly improve your coding efficiency. If you prefer to emacs
, you can download and install emacs
from network mirrors.
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
PRACTICE IS VERY IMPORTANT. You can not learn anything by only reading the tutorials.
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:
为什么要先上网搜索?
你或许会想, 我问别人是为了节省我的时间.
但现在是互联网时代了, 在网上你能得到各种信息: 比如 diff 格式这种标准信息, 网上是 100% 能搜到的; 就包括你遇到的问题, 很大概率也是别人在网上求助过的. 如果对于一个你本来只需要在搜索引擎上输入几个关键字就能找到解决方案的问题, 你都没有付出如此微小的努力, 而是首先想着找人来帮你解决, 占用别人宝贵的时间, 你将是这个时代的“失败者”.
于是有了 STFW (Search The F***ing Web) 的说法, 它的意思是, 在向别人求助之前自己先尝试通过正确的方式使用搜索引擎独立寻找解决方案.
正确的 STFW 方式能够增加找到解决方案的概率, 包括
如果你没有使用上述方式来 STFW, 请不要抱怨找不到解决方案而开始向别人求助, 你应该想, “噢我刚才用的是百度, 接下来我应该试试 Google”. 关于使用 Google, 在学校可以尝试设置 IPv6, 或者设置“科学上网”, 具体设置方式请 STFW.
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.
为什么要这么麻烦?
搞了半天, 你发现其实也就是改动一个字符而已, 干嘛不直接说清楚呢?
这是为了“入乡随俗”: 我们希望你了解怎么用计算机思维精简准确地表达我们想做的事情. diff 格式是一种描述文件改动的常用方式. 实际上, 计算机的世界里面有很多约定俗成的“规矩”, 当你慢慢去接触去了解这些规矩的时候, 你就会在不知不觉中明白计算机世界是怎么运转的.
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.
提高开发效率的编辑器
程序设计课上你学会了使用 Visual Studio, 然后你可能会认为, 程序员就是这样写代码的了. 其实并不是, 程序员会追求那些提高效率的方法. 不是 GUI 不好, 而是你只是用记事本的操作方式来写代码. 所以你需要改变, 去尝试一些可以帮助你提高开发效率的工具.
在 GNU/Linux 中, 与记事本的操作方式相比, 学会vim
的基本操作就已经可以大大提高开发效率. 还有各种插件来增强vim
的功能, 比如可以在代码中变量跳转的ctags
等等. 你可以花点时间去配置一下vim
, 具体配置方式请 STFW. 总之, “编辑器之神”可不是浪得虚名的.
We present the modification with . If you do not understand the diff format, please search the Internet for more information.
使用 搜索引擎搜索一般性问题
使用查阅概念
使用 问答网站搜索程序设计相关问题