DEV Community

Cover image for How to learn Vim with examples
Steadylearner
Steadylearner

Posted on • Updated on • Originally published at steadylearner.com

How to learn Vim with examples

When I first tried to learn Vim, it was not easy at all.I couldn’t have total control that I had with other IDE such as VSCode.

Then, I repeated several times with desire to learn it but failed to maintain what I learnt later. But, I had to use it to deploy websites and I could learn it really.

I just remembered what an experienced developer told before.

“You learn something better when you have to work with real projects”

I had to use it to solve what was difficult for me with Vim to really learn it.

While using it for real projects, I did find its benefits.

  • It is already installed almost on every system. You don’t have to install it for a new dev environment.

  • It doesn’t need much HD and works very well with less resources.

  • It is better at solving simple problems when you are already accustomed to use it.

Table of contents

  1. Where to begin?
  2. List of minimal Vim commands
  3. Conclusion

1. Where to begin?

begin

I think this website can be very useful for beginners.

First, it is very interactive and you can control your learning phase and back to previous process easily.

Second, there are even practice pages for you to use what you learnt.

I have repeated this several times before I had to start the real project.

You can visit it first or after reading List of Vim commands below.

Then, you can verify what you learnt with $vimtutor command.

vim tutor

It is very helpful to start to learn Vim with it. I hope you to go on until lesson 2 at least and hope you already know how to navigate and edit texts.

If you followed them well, you already know Vim sufficiently to use at real work. But, I want to give you minimal Vim commands to remember.

2. List of minimal Vim commands

type

Photo by Kaitlyn Baker

1. Controlling Cursors

When you open files with $vim test.txt Vim starts with editor mode. You can use I to start with insert mode and back to editor mode again with [Esc] or ctrl + [ commands.

You can move cursors with these when you are in editor mode. It will take sometime to be familiar with them.

⬅ h to left, 
⬇ j to down
⬆ k to up
➡ l to right
Enter fullscreen mode Exit fullscreen mode

You can also use ⬅ ⬇⬆ ➡ on keyboard instead whether you are in Editor Mode or not.

2. Write, Save and Quit from the Vim

Writing what you want with Vim, you need to save it and quit from the vim.

To do that, you need to use these.

  1. $vim test.txt
  2. push [i] on keyboard to switch from normal mode to insert mode.
  3. Write something.
  4. push [Esc] to back to normal mode.
  5. push [shift + :] + wq(:wq) to write and quit

Repeat this process until you become familiar with it.

3. Switch between the end and the beginning of the file

When you want to write more contents for existing files, you will start with the end of file.

You can start it with ‘G’ and “gg”* to back to the beginning of the file.

You can combine this with ‘d’ command to delete every lines with gg ➡ dG and it will clear file for you and you don’t have to make a new one.

4. Commands used to delete

They are used when it is not in editor mode(You can stop editor mode with ESC).

  1. ‘x’ to delete a word below the cursor
  2. I already showed use case of ‘d’ above. It can be combined with other keys.

For example, you can test them.

  • “dw” to delete a word
  • “d$” to delete a line after current cursor postion
  • You can also use ‘C’ instead to the same as “d$” \
  • “cc” to remove a line and to use Insert Mode
  • ‘r’ to replace a character below the current cursor position

When you use delete relevant commands they are saved to the clipboard.

You can use ‘p’ to paste it and later you can paste again with either ‘p’ or ‘.’ to repeat previous command.

You can use ‘u’ for undo when something went wrong and redo with [ctrl + shift + r].

5. find a specific word with ‘/’

search

Photo by Jordan Hile

You can use ‘/’ in [Normal Mode] to find some words and you can use ’n’ to move to the next and ’N’ to the previous.

You can also combine numbers with them. You can test it locally.

test

6. ‘A’ to append a word at the end of the current line

It is useful to correct missing trailing , or ; etc when you edit a file.

7. Commands to end the process

  1. :w to write, which means save the file and :q to quit without saving
  2. :wq to write, save and quit (You will use this normally.)

These were the commands for beginners I thought useful.

You will need to use the editor mode to write texts and the normal mode mostly.

Be calm and verify well which mode you are and think before you type something if something went wrong. You can always use ‘u’ in the normal mode to undo something.

3. Conclusion

end

Photo by Al x

I hope you complete the post well. I want to tell you that you don’t need a lot of time to start to use Vim.

Just practice first and use it inside your own project. In time, You will find that you are already using it well.

If you need to hire a developer, you can contact me.

I can write a full stack dapp.

Thanks.

Top comments (1)

Collapse
 
computergeek profile image
Amrut

yeah i tried using that web site that's really nice for beginners.