// 2023-08-5 // by Makkor Jamal
This quote is from the legendary answer in Stackoverflow Here where the author explains how to actually undestand vim. Once you do you will always program/modfiy text at the speed of your thought.
I do my programming almost exclusively using vim. You dont need a mouse or a numerical pad. Only your keyboard and you are good to go. If you use directional keys dont let anyone know. It is a mortal sin ans if your older colleague uses emacs, avoid the vim subject altogether.
Vim undestands human language (sort of). But first let me get the meme out of the way. If by any happenstance you found yourself inside VI like editor don’t panic click on escape twice -once is enough but twice just to be sure- and then type :q! end enter, voila, you are out. But if you decide to use vim then proceed.
Vim has several modes that allow users to interact with text in different ways. The primary modes are:
Normal Mode: This is the default mode when you open Vim. In this mode, you can navigate through the text, delete, copy, paste, and perform other commands. You enter Normal Mode by pressing Esc.
Insert Mode: In this mode, you can insert text into the document. You can enter Insert Mode by pressing i (insert before the cursor), I (insert at the beginning of the line), a (append after the cursor), or A (append at the end of the line). You return to Normal Mode by pressing Esc.
Visual Mode: This mode allows you to select text. You can enter Visual Mode by pressing v (character-wise selection), V (line-wise selection), or Ctrl + v (block-wise selection). You can then perform operations on the selected text. Pressing Esc will return you to Normal Mode. Command-Line Mode: In this mode, you can enter commands for Vim, such as saving, quitting, or searching. You enter Command-Line Mode by pressing : in Normal Mode. After typing your command, press Enter to execute it.
Replace Mode: This mode allows you to replace existing text as you type. You can enter Replace Mode by pressing R in Normal Mode. You can return to Normal Mode by pressing Esc. Select Mode: This is similar to Visual Mode but behaves more like text selection in other editors. You can enter Select Mode by pressing gh in Normal Mode. You can then select text and perform operations, returning to Normal Mode with Esc.
Maybe there are other modes.. You never know with vim there is always something new to discover
##enter and talk to vim
I will assume that you are using linux and that you want to modify a text file. Then call vim using vim file.txt
. Now you are inside vim. But you know how to exit so I am not worried. Let’s say you wrote a large portion of code then you want to start modifying. First thing avoid using directional keys ← → and ↑ ↓ instead use jkhl to move up and down, left and right. It is for a good reason. Using directional keys is called an anti-pattern because you will type slower (all of your instant reach and all of that). But a better way to move is by word using w, end of the word using e and backwards using b. Now you want to modify you can talk to vim. Tell it I want to modify a whole word by typing escape (in case you are in insert mode) and writing ciw or change inner word. write what you want and then if you want to apply this change in multiple places using the . button
There is also diw (Delete inner word) replace w with W to select Big Words ( which are words up to space) e with E and b with B etc you get the gest. you can apply this to all cip for paragraphe. ci}“[ to modify code inside these types of brackets or di}”[ to delete. Dont forget to be inside the normal mode to do all of this. I am still learning vim (dont get me started on vim plugins and vim script). I hope you enjoyed this tutorial as much as I enjoy working with vim.