VIM tips & tricks

VIM tips & tricks

Vim has two basic modes. One is insert mode, in which you write text as if in normal text editor.

Another is normal mode which provides you efficient ways to navigate and manipulate text.

At any time, you can see which mode you are in on the status bar which is located at the top or bottom of the editor.

To change between modes, use Esc Key for normal mode and i for insert mode.

In contrast to regular text editor, you use keys h, j, k, and l instead of arrow keys to move the cursor.

To navigate the text in terms of words, you can use keys w, b, and e (also W, B, E in real Vim).

w moves to the start of the next word; e moves to the end of the word; and b moves to beginning of the word.

Moving within the text is not limited to individual keys; you can combine movement keys with a number. For example, 3w is the same is pressing w three times.

You can insert text multiple times. For example, an * of a header might consist of 75 *.

With 75 i * Esc, there's no need to press * 75 times. It produces the following result.

***************************************************************************

To find and move to the next (or previous) occurrence of a character, use f and F, e.g. fo find next o.

You can combine f with a number. For example, you can find 3rd occurrence of 'q' with 3fq, que?

In text that is structured with parentheses or brackets, ( or { or [, use % to jump to the matching parenthesis or bracket.

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.

Not go to the beginning of this screen with gg and then back to the end with G.

Go to line 2 with 2G.

Searching text is a vital part of any text editor. In Vim, you press /, and give the text you are looking for.

You can repeat the search for next and previous occurrences with n and N, respectively.

For advanced use cases, it's possible to use regexps that help to find text of particular form (In real Vim).

Let's try a simple text search.

Search for text and find the subsequent matches with n.

To insert text into a new line, press o or O.

After new line is created, the editor is set to insert mode.

Write a bit and get back to normal mode.

x and X delete the character under the cursor and to the left of the cursor, respectively

Try pressing x to remove the last word.

Sometimes the treasure is the indicator (x).

When you need to replace only one character under your cursor, without changing to insert mode, use r.

d is the delete command

You can combine it with movement, e.g. d w deletes the first word on the right side of the cursor.

It also copies the content, so that you can paste it with p to another location (on real Vim).

It is gone now. Now let's remove two words with d2e.

To repeat the previous command, just press .

First, remove two words with d 2 w.

After that, remove the rest of the words in this line with .

Repetition is the root of all periods . command.

Besides insert and normal mode, Vim has also Visual mode.

In visual mode, you select text using movement keys before you decide what to do with it. Let's see how. Go to visual mode with V. Then select a word with e. After you've selected the text, you can delete it with d. This sentence has not seen the light.

Now you should be quite confident to enter the real Vim.

Most important commands to remember are : w ( save ), : q ( quit ), and : q! ( quit without saving ).

Also don't PANIC If you make a mistake, press u for undo and ctrl + R for redo

If you have, or want to learn more about what Vim offers, type : help

Thanks => [email protected]

要查看或添加评论,请登录

Velmurugan Kuberan的更多文章

  • Popup for Youtube and Vimeo

    Popup for Youtube and Vimeo

    This Wordpress shortcode plugin helps you to add Youtube or Vimeo videos on an HTML link. When that link is clicked…

社区洞察