Vim
为什么学习 Vim
在我看来 Vim 编辑器有如下的好处:
- 让你的整个开发过程手指不需要离开键盘,而且光标的移动不需要方向键使得你的手指一直处在打字的最佳位置。
- 方便的文件切换以及面板控制可以让你同时开发多份文件甚至同一个文件的不同位置。
- Vim 的宏操作可以批量化处理重复操作(例如多行 tab,批量加双引号等等)
- Vim 是很多服务器自带的命令行编辑器,当你通过
ssh连接远程服务器之后,由于没有图形界面,只能在命令行里进行开发(当然现在很多 IDE 如 VS Code 提供了ssh插件可以解决这个问题)。 - 异常丰富的插件生态,让你拥有世界上最花里胡哨的命令行编辑器。
如何学习 Vim
不幸的是 Vim 的学习曲线确实相当陡峭,我花了好几个星期才慢慢适应了用 Vim 进行开发的过程。最开始你会觉得非常不适应,但一旦熬过了初始阶段,相信我,你会爱上 Vim。
Vim 的学习资料浩如烟海,但掌握它最好的方式还是将它用在日常的开发过程中,而不是一上来就去学各种花里胡哨的高级 Vim 技巧。个人推荐的学习路线如下:
- 先阅读这篇 tutorial,掌握基本的 Vim 概念和使用方式。
- 用 Vim 自带的
vimtutor进行练习,安装完 Vim 之后直接在命令行里输入vimtutor即可进入练习程序。 - 最后就是强迫自己使用 Vim 进行开发,IDE 里可以安装 Vim 插件。
- 等你完全适应 Vim 之后新的世界便向你敞开了大门,你可以按需配置自己的 Vim(修改
.vimrc文件),网上有数不胜数的资源可以借鉴。
推荐参考资料
- Neil, Drew. Practical Vim: Edit Text at the Speed of Thought. N.p., Pragmatic Bookshelf, 2015.
- Neil, Drew. Modern Vim: Craft Your Development Environment with Vim 8 and Neovim. United States, Pragmatic Bookshelf.
Vim
Why Vim
In my opinion, the Vim editor has the following benefits:
- It keeps your finger on the keyboard throughout the development and moving the cursor without the arrow keys keeps your fingers in the best position for typing.
- Convenient file switching and panel controls allow you to edit multiple files simultaneously or even different locations of the same file.
- Vim's macros can batch repeat operations (e.g. add tabs to multi-lines, etc.)
- Vim is well-suited for Linux servers without GUI. When you connect to a remote server through
ssh, you can only develop from the command line because there is no GUI (of course, many IDEs such as VS Code now providesshplugins to solve this problem). - A rich ecology of plugins gives you the world's most fancy command-line editor.
How to learn Vim
Unfortunately Vim does have a pretty steep learning curve and it took me a few weeks to get used to developing with Vim. You'll feel very uncomfortable at first, but once you get past the initial stages, trust me, you'll fall in love with Vim.
There is a vast amount of learning material available on Vim, but the best way to master it is to use it in your daily development, no need to learn all the fancy advanced Vim tricks right away. The recommended learning path is as follows:
- Read This tutorial first to understand the basic Vim concepts and usage.
- Use Vim's own
vimtutorto practice. After installing Vim, typevimtutordirectly into the command line to enter the practice program. - Then you can force yourself to use Vim for development, and you can install Vim plugins in your favourite IDE.
- Once you're fully comfortable with Vim, a new world opens up to you, and you can configure your own Vim on demand (by modifying the
.vimrcfile), and there are countless resources on the Internet to learn from.
Recommended References
- Neil, Drew. Practical Vim: Edit Text at the Speed of Thought. N.p., Pragmatic Bookshelf, 2015.
- Neil, Drew. Modern Vim: Craft Your Development Environment with Vim 8 and Neovim. United States, Pragmatic Bookshelf.