Vim Notes Multiple lines

Source: Internet
Author: User
Tags imap

As a non-professional operations personnel, miserable for the forgotten operation and regret, hence reproduced!

From:http://www.21andy.com/blog/20100413/1859.html

Vim notes Multi-line simplification instructions
The following comment 3 line operation is as follows

Esc
0 jump to the beginning of the line
Ctrl + V Visual block mode
JJJ Move Down 3 rows
I Enter insert mode
//
Esc

Too much trouble to define shortcut keys yourself

# Vim ~/.VIMRC

Enter the following to save

"F5 for comment
Vmap <F5>: s=^\ (//\) *=//=g<cr>:noh<cr>
Nmap <F5>: s=^\ (//\) *=//=g<cr>:noh<cr>
IMAP <F5> <esc>:s=^\ (//\) *=//=g<cr>:noh<cr>
"F6 for Uncomment
Vmap <F6>: s=^\ (//\) *==g<cr>:noh<cr>
Nmap <F6>: s=^\ (//\) *==g<cr>:noh<cr>
IMAP <F6> <esc>:s=^\ (//\) *==g<cr>:noh<cr>

Vim Comment Multiline Detailed description:
CTRL + V enters the column mode, moves the cursor down or up, marks the beginning of the line that needs comment, then presses the uppercase I, then inserts the comment, such as #, and then presses ESC, which is all commented. Alternatively, you can run the following commands:

: s/^/# #用 "#" comment when moving forward
: 2,50s/^/# #在2 ~50 Add "#" comment
:., +3s/^/# #用 "#" comment the current line and three rows following the current line
:%s/^/# #用 "#" Comment all rows

By the way, the replacement of vim, this common, has been kept in mind, in fact, and the above with the command comment Multiline is the same, but the above comment on the command "^" symbol represents the starting position, in the following commands, "S" represents the replacement, Part1 represents the content of the search, Part2 represents the replacement of the content, " % "represents all rows," G "represents the replacement of all the contents of the entire line (if no"/g "is substituted for only the first matching part1 of each row).

: S/part1/part2 #用part2替换当前行中第1个part1
: s/part1/part2/g #用part2替换当前行中所有的part1
:%s/part1/part2 #用part2替换所有行中每行第1个part1
:%s/part1/part2/g #用part2替换所有行中所有的part1
: 2,50s/part1/part2 #用part2替换第2行到第50行中每行第1个part1
: 2,50s/part1/part2/g #用 part2 Replace all part1 in line 2nd through 50th
:., +3s/part1/part2 #用part2替换当前行以及当前行后面的三行中每行第1个part1
:., +3s/part1/part2/g #用part2替换当前行以及当前行后面的三行中所有的part1

BTW: When replacing, be aware that some characters need to be translated, such as spaces, parentheses, and so on.

Vim Notes Multiple lines

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.