Trying out Vim

A life long learner and tech tinkerer. Making and breaking systems. Learning from mistakes.
Search for a command to run...

A life long learner and tech tinkerer. Making and breaking systems. Learning from mistakes.
Thank you. Hope this will help you.
Thank you for the suggestion.
Elixir is a functional programming language. Functional languages are built with functions as first-class citizens and tend to involve a declarative style of programming, where we specify what is to b

So... I’m blogging again. It’s been a while. Maybe longer than I’d like to admit. If you’ve ever stepped away from technical blogging or any creative outlet, you’ll understand the weird cocktail of excitement and hesitation that comes with coming bac...

Fundamentals and The Rise of Agentic AI

Switching from Visual Studio Code (VSCode) to Neovim as your main IDE can be a transformative experience. While both editors have their strengths and weaknesses, many developers find that Neovim offers a unique blend of speed, customizability, and ke...

If you are starting out with Next.js and Server Side Rendering for the first time, then the initial project setup may take a significant amount of your time. It is not likely that you will be working with plain Next.js. You should require some toolin...

Vim (Vi IMproved) is a highly configurable text editor built to make creating and changing any kind of text very efficiently. It is included as "vi" with most UNIX systems and with Apple OS X.I attempted to learn Vim quite a few times before but could not cope up with it. But recently I thought I should at least know very basic usage of Vim. So I started learning the absolute basics. Here I am putting all the basic commands and usage of Vim for any absolute beginner like me. This can be helpful to get started with Vim I think. But there is a lot of things to learn about this handy tool that will take much time and practice. One will get proficient in using Vim only by using it consistently.
Vim has two basic modes:
INSERT mode, in which you write text as if in a normal text editor.NORMAL mode which provides you efficient ways to navigate and manipulate text. This is also called Command mode cause we can do various vim commands on this mode.To change between modes, use ESC for normal mode and i for insert mode.
| Command | Action |
| :e filename | Open filename for editon |
| :w | Save file |
| :q | Exit vim |
| :q! | Quit without saving |
| :x | Save and Exit |
| :sav name | Save current file as name |
| . | Repeat last change made in NORMAL mode |
h to move cursor left (←)l to move cursor right (→)k to move cursor up (↑)j to move cursor down (↓)b moves to the beginning of the worde moves to the end of the wordw moves to the beginning of the next wordUsing a number before each command can execute that command that many times. e.g 3w will move to the 3rd next word.
To insert the same text multiple times use <number>i<text>esc. e.g 3<i>go<esc> will write gogogo.
To find and move to the next (or previous) occurrence of a character, use f and F, e.g. fo finds next 'o'. You can combine f with a number. e.g. you can find 3rd occurrence of 'q' with 3fq.
In text that is structured with parentheses or brackets, ( or { or [, use % to jump to the matching parenthesis or bracket.
To reach the beginning of a line, use 0. For the end of line use $.
Find the next occurrence of the word under the cursor with *, and the previous with #.
gg takes you to the beginning of the file; G to the end. To jump directly to a specific line, give its line number along with G. e.g 5G will take you to the fifth line of the file.
Searching text is a vital part of any text editor. In Vim, press /, and give the text to search for. The search can be repeated for next and previous occurrences with n and N respectively. For advanced use cases, it's possible to use regexps that help to find the text of a particular form.
To insert text into a new line after the current line use o and to insert a new line before the current line use O.
After a new line is created, the editor is set to insert mode.
x and X delete the character under the cursor and to the left of the cursor, respectively.
Also adding a number before x of X can perform the action that many times. e.g 5x will remove the next five characters including the character under the cursor and 5X will remove the previous five characters excluding the character under the cursor.
User r to replace only one character under the cursor.
d is the delete command. It can be combined it with movements, e.g. dw deletes the characters on the right side of the cursor up to the beginning of the next word. de deletes all the characters of the word on the right side of the cursor including the character under cursor. db will delete the previous word if the cursor is under the first letter of a word or else it will delete the characters left to the cursor upto the beginning of the word.
It also copies the content, so that you can paste it with p to another location.
dd will delete the whole line.
To repeat the previous command, just use . (period).
Use R to enter REPLACE mode. In this mode characters under the cursor can be replaced.
Use v to enter the VISUAL mode and V to enter VISUAL LINE mode. In this mode the text can be selected by the movement keys before deciding what to do with it.
Selected text can be deleted/cut using d or copied using y. It can be pasted after the cursor using p or before the cursor using P.