Vim is a popular lightweight and powerful text editor on Linux systems. I use Vim mainly for quick editing of small files, such as configuration files or script files, but it can of course be used for any text editing. This is a beginner’s guide, just scratching the surface of Vim

Start Vim

Start Vim and create the file newfile.txt, or edit it (if it already exists)

vim newfile.txt

Tips: vim newfile.txt +3 will open the file and directly put the cursor on line 3

Insert mode and normal mode

One thing that makes Vim different from many other editors is the mode. In this article I will only mention normal mode and insert mode, but there are more modes.

When you start Vim, you will automatically enter normal mode.

To enter text, you need to be in insert mode. Just press the i key or insert button to enter the insert mode. Now enter some lines in the editor.

Tip: Have you forgotten whether you are in normal mode or insert mode? Check the message in the lower left corner of the ==INSERT== window

image.png

To enter normal mode again, press esc

Browse text in normal mode

You browse the cursor arrow keys or use the h, j, k and l keys:

  • h-move left
  • j-move down
  • k-move up
  • l-move right

There is no problem using the arrow keys at all, but hjkl recommends an alternative method for quick navigation, because usually the arrow keys are located far away from the letter keys, so it takes more time to get there. However, it takes some time to get used to using hjkl instead of arrows. Try it

More navigation options:

  • G-go to the last line of the document
  • gg-go to the beginning of the document
  • 3G-go to line 3
  • 20l- Go to the 20th column to use 20l

Note: 20l simply means to repeat the l command 20 times

Search term

To search for the word "friend" from the normal mode, type /Friend and press Enter. If the word "Friend" appears in the document, the cursor will go to its first position. If you are familiar with the less program, you will be able to search for documents in Vim in a similar way.

Note: By default, the search is case sensitive

Save and exit Vim

To save the current file and exit, enter :wq from normal mode. (If you are not in normal mode, enter esc, then enter :wq)

点赞(0)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部