10 + Tips to save time for vim novice

Source: Internet
Author: User

10 + Tips to save time for vim novice2016-04-28 Linux Enthusiasts

(Click the public number above for a quick follow-up)

from: Specs ' blog-love PHP

Links: http://9iphp.com/linux/time-saving-tips-for-unix-vim-beginners.html

Vim is the preferred editor for many developers, and it helps you get the job done faster by setting the right commands and shortcuts. In this article, we offer some tips on how to improve your productivity by providing new shortcuts to Vim novices.

1. Configure VIMRC

When I first used vim, I wasted a lot of time to indent the code, and I didn't know that by modifying Vim's. VIMRC configuration file, you can indent code, syntax highlighting, and display line numbers.

Create a. vimrc file in your Home directory, add the following code to set the line number, indent the code, and so on.

Set Number # Displays line numbers

Set Autoindent # Auto Indent

Set NoWrap # no Line break

2. Do not close the terminal exit editor

Saving and exiting the edit state using the Vim editor is a breeze, just remember to press ESC to switch to normal mode, then enter a colon (:), then enter WQ to save and exit.

: Wq

If you do not want to save, press ESC to switch to normal mode, and then enter a colon (:), then enter q!.

: q!

3. Delete one or more rows

Removing a line of code through the backspace bar (Backspace) is obviously too much of a hassle. You can do this by switching to normal mode (press the ESC key in edit mode):

DD: (Enter two times D, same as below) to delete the current line; 5DD: Delete 5 rows from the current line;

DG: (Enter D first, then press SHIFT to enter G) to delete the current line to the last row.

4. Copy and paste a piece of code

You may often need to copy a line or a chunk of code, and using Vim shortcut keys to implement this feature is very simple:

Press ESC to switch to normal mode;

Move the cursor to the beginning of the code you want to copy;

Press V to select the entire row, move the cursor to select multiple rows;

Press D to cut or press Y to copy the selected code;

Move the cursor to where you want to paste it, press p to paste the code to the position after the cursor, or press p to paste it before the cursor.

5. Undo and Redo

When using Vim or other editors, you may often need to undo or redo some of the changes. In Vim, you can switch to normal mode, press U to undo the operation, and press Ctrl+r to redo.

6. Code comments

Code Comment:

Press CTRL + V to switch to visual mode;

Move the cursor (j or k) to the beginning of the line you want to annotate;

Press uppercase I, and then enter an annotation symbol, such as #, and finally press ESC.

Uncomment:

Press CTRL + V to switch to visual mode;

Press J or k to select an annotation to delete;

Press D or X to remove the comment character

If you use the//symbol comment, you need to do two times to uncomment the comment.

7. Search

Search is a very important feature in many cases. Search for a specific word in the file, you can switch to normal mode, then enter a slash (/), followed by the word to search, enter.

/word-to-be-searched

Press N to display the next search result, and press N to display the previous search results.

8. Read the external file into Vim

When I started using Vim, I often opened a file, copied the content, closed the file, opened another file, and then pasted it into the content. In fact, it is very convenient to read the contents of another file in Vim. Switch to normal mode, and then press: Read. Using this shortcut you do not need to manually open the file to copy the content.

: Read readme.md

9. Read the results of the command into Vim

Sometimes you need to copy the results of a command into Vim, which is very simple in vim. Switch to Normal mode and enter: Read!command to input command results into VIM.

: Read!ls-l

10. Switch to the last modified location

Want to know where you made the last modification in the file? Switch to normal mode and enter G; To switch to the location you last modified.

11. Move to the top or bottom of the file

When you need to move to the top or bottom of a file, it's a bit cumbersome to move through a line of J or K. Vim provides a shortcut key to directly implement this function. Switch to normal mode, enter GG to return to the top of the file, enter G to return to the bottom of the file.

10 + Tips to save time for vim novice

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.