If you are a developer, use Linux, or love old software, you have probably heard of Vim or similar text editors. Vim is the successor to Vi, which has been around since the mid-70's. The learning curve initially is very steep, as it does not behave as one would expect coming from modern, GUI-based editors. The popularity of a StackOverflow answer on exiting Vim eases the suffering of many who attempt to use Vim for the first time: https://stackoverflow.com/questions/11828270/how-to-exit-the-vim-editor
Exiting Vim
The first and most important task to know how to do in Vim is exiting. Start by pressing Esc a few times to make sure you are in normal mode. Next, enter :q!(Enter). This command starts by entering command mode using ":" followed by "q!" indicating you would like to force quit without saving. Saving can be done with a similar command ":wq myFileName.txt" if you are saving the file for the first time, or ":wq" if you are saving the same file again. Entering "ZZ" from normal mode performs the same action in one less character (technically the same number of keystrokes since you have to hold down shift while pressing z).
Baby Steps
Getting started with Vim can be very straightforward using the correct tool. Vimtutor comes with Vim and is a great starting point. Opening a console and typing the command "vimtutor" will open a document in Vim that will guide you through the basics.
Let's Get Modal
Modal editors work by allowing keyboard keys to have different purposes inside different modes. When you open Vim, you normally start in... well... normal mode. As the name suggests, you will be spending a lot of time in normal mode if you use Vim to edit files. In normal mode, you can move about the file very easily using Vim's motions and enter the other modes. To get back to normal mode, all you need to do is press Esc. The modes of Vim are as follows:
- (Esc) - Normal Mode is used to enter other modes and move about the document.
- (i,c,a) - Insert Mode is used to enter text. Most motions are disabled in this mode in case you need to insert one or more of those characters into the document
- (v) - Visual mode is used to select text.
- (:) - Command mode is used to enter commands
Motions
Your most common action inside normal mode will be movement. With some practice and a few keystrokes, you can position your cursor exactly where you want it and begin deleting lines of text, making edits, or making new additions. Many of Vim's motions can be combined with commands, allowing you to perform complex editing tasks that would normally require removing your hand from the keyboard and using the mouse several times.
Arrow Keys and Directional Motions
Arrow keys are a touchy subject for some Vim users, as Vim purists do not like to leave home row at all. For purists, they insist on using h (left), j (down), k (up), and l (right) since these are easier to reach. Arrow keys serve the same purpose, however.
Wordwise Motions
Wordwise motions are pretty straightforward. While in normal mode, "w" will move the the cursor one word to the forward. A word is considered a group of numbers and letters that are not separated by whitespace or other delimiters (e.g. note the difference: "these are words"/"thisIsOneWord"). Vim distinguishes between "WORDS" and "words." WORDS have only whitespace as a delimiter, meaning that "3.1415" would be treated as one WORD. Using a word motion on this string would require pressing "w" multiple times to get through it. Moving by a WORD instead of by word is accomplished through capitalizing the motion, making the motion far more efficient in circumstances where non-whitespace delimiters get in the way. Now that we have reviewed the difference between WORDS and words, the wordwise motions can be described as follows:
- (w/W)ord--Move cursor one word/WORD forward (i.e. to the beginning of the following word)
- (e/E)nd of word--Move cursor to the end of the current word/WORD
- (b/B)ack a word--Move cursor back one word/Word
(F)ind
There is one more motion that bears mentioning at this stage of your journey to becoming a vim fu master. Find is an interesting one. Find waits for you to enter another character before executing and searches the line your cursor is on for the first instance of the character you entered. An example would be useful here. Let's assume that my cursor is at the beginning of the sentence below. Pressing "fe" places my cursor in front of the "e" in Berliner. Far more efficient than trying to use wordwise motions.
I am a Berliner.
Next time, we will cover normal mode commands and combining them with motions.
Learning Resources
The first, best, and most obvious place to get overloaded on Vim info is Vim's documentation.
There are a number of great screencasts on YouTube, but Vimcasts are worth a look if you want to get Vim-specific content.
Learning by doing is the best way to learn, so I am going to mention this one again: vimtutor is a great resource.
Congratulations @iamzerg! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP