Common operations for Vim

Source: Internet
Author: User

Common operations for Vim

I. Find and Replace in vim
    • Modify when moving forward

      :s/str1/str2/

      Modifies the first str1 of the current line to STR2

      :s/str1/str2/g

      Modifies all str1 of the current line to STR2

    • Modify line N to line M

      :n,ms/str1/str2/

      Modify the first str1 of line N to line m to str2

      :n,.s/str1/str2/

      Modifies the first str1 of the nth row to the current line as str2

      :.,ms/str1/str2/

      Modifies the first str1 of the current line to row m to str2

      :n,$s/str1/str2/

      Modify the first str1 of the nth line to the last line as str2

PS: If you are modifying all of the lines str1 str2 , add g to the back

    • Replace each row

      :%s/str1/str2/

      Modify the first str1 of each row to str2

      :1,$s/str1/str2/

      Modify the first str1 of each row to str2

PS: If you are modifying all of the lines str1 str2 , add g to the back

    • The complete form of VIM's replacement command

      :[range]s/from/to/[flags]

ranges: The above has been mentioned
From : regular expressions can be used
To : the character to be replaced
flags: as shown below, these several combinations can be used

无      :  只对指定范围内的第一个匹配项进行替换。g       :  对指定范围内的所有匹配项进行替换。c       :  在替换前请求用户确认。e       :  忽略执行过程中的错误。
Two. Vim's common shortcut keys
    • Jump

1. Basic upper and lower left and right
j: On
k: The next
h: Left
l: Right

2. Turn One page
ctrl + f: Turn one page forward (forward)
ctrl + b: one page back (backward)

3. Turn Half page
ctrl + u: Turn half page forward (UP)
ctrl + d: Half page backward (down)

4. Turn the line
ctrl + e: Turn down one line
ctrl + y: Turn up one line

5. Jump to the definition of functions and variables
[ + ctrl + i: Jump To Definition
[ + ctrl + d: Jump to # define place

6. Cursor Jumps
ctrl + i: Jump Forward
ctrl + o: Jump Backwards

7. Jump in function body
[{: Jump to function Body header
]}: Jumps to the end of the function body
[[,,, ]] {{ }} , invert function body

8. Jump Words
b: Go to the [B]eginnig of this word
e: Go to the [e]nd of this word
w: Go to the start of the following word

    • Selected

1. Selected ctrl + v by the adjustment of the upper and lower left and right commands

2. shift + v Select in the mode
vi(: Select the contents of the parentheses, excluding the parentheses
va(: Select the contents of the small brackets, including the parentheses , below
vi[
va[
vi{
va{
vi‘
va‘
vi"
va"

Common actions for Vim

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.