Vim Part 1
We will cover the following topics in this two-part tutorial:
Part 1 Practice First Week
Why Vim?
Editor wars
How to learn and practice
Vim modes
Navigating in Vim
Cool features: tabs, folds and screen splits
Basics of copying and undo redo
Part 2 Practice Second Week
Deleting in Vim
Replacing in Vim
Multi-line cursor
Macros (killer feature)
Why Vim?
Vim is ubiquitous and Vim is fast. By "ubiquitous," I mean Vim is available everywhere. Ssh into a remote terminal and you have Vim; you have a raspberry Pi and you have Vim. You don't need a powerful machine for Vim. It's great for programmers, writers, and DevOps engineers. What you are learning is not only Vim but also some really useful key bindings. If you use vanilla Vim, it works great with Python, JavaScript, CSS, C++/C, HTML and many more.
I believe Java folks should be fine using Vim emulation in VSCode or IntelliJ, since the auto-completion plugins requires Java 11 and many of you might not be on Java 11 yet. Whenever I am doing some text edits which don't need auto completion, I fire up my Vim to edit Java quickly. You have to use it in order to believe the speed of this editor.
With a little bit of configuring, you can get autocomplete etc. to work. But that is not the point of this article. I will help you with the basics of Vim before we dive into language specifics in the future articles.
A note about being fast: "Faster" doesn't mean you will type faster or that the editor is more responsive. "Faster" means you'll free up time for more meaningful work than meaningless keystrokes. Your brain cycles should be focusing on the problem instead of constantly context switching between thinking about editing something between braces, creating new lines, or how to copy, paste. For example, switching to a mouse for pointing to the right object on screen constitutes a context switch.
Editor wars
Whether you are a power sublime user, Emacs user, IntelliJ, or Eclipse user with muscle memory developed for these editors/IDE, you are a great developer too. You don't need Vim, and you can stop reading. If you believe that you could improve your workflow because text editing is the most tedious task as a programmer, then read along.
Vim is not a religion.
How to learn and practice
- Just type "vimtutor" in your terminal on *nix computer and follow the instructions. In Windows use a git bash terminal.
- Install the Vimium plugin in your Chrome browser.
- You can install Vim plugins in VSCode and IntelliJ Idea. True! You don't have to give up on your favorite IDE and still be better.
Vim plugins are very popular on both VSCode and IntelliJ.
- Read this article to avoid Googling random stuff on the internet. I will be honest and true to my word to make this an informative and enjoyable read for you. Hang in here with me.
Don't be discouraged if something does not work. Be patient and work with this editor for two (2) weeks. Your productivity will grow many folds with this investment. I learn at least one new thing every week with Vim.
Vim Modes
Vim is modal text editor which means it has several modes.
- Normal Mode: You'll be in this mode most of the time. It's good for you. This is the default mode when Vim is launched
- Visual Mode: Use this mode if you are more visual person and want to see what's going on
- Insert Mode: Use this mode to insert text. Spend the least amount of time as you can in this mode
- Command Mode: Use this mode to execute certain commands, such as saving file, etc.
- Replace Mode: Use this mode to replace text on screen (buffer)
Switching modes:
- Normal Mode to Insert Mode: Press i in Normal mode to switch to insert mode
- Insert Mode to Normal Mode: Press Esc to go back to Normal mode
- Normal Mode to Visual Mode: Press v in Normal mode
- Normal Mode to Command Mode: Press Esc + : to enter command mode
- Insert Mode to Visual Mode: Switch to Normal mode first and then press v
- Normal Mode to Replace Mode: Press R to enter replace mode
Click to see demo |
Phew! Was that a lot? It was for me at first. Think of it as an investment. You just covered the most important part of Vim, which are its modes.
Comments
Post a Comment