海思vi不绑定vpss_通过学习这30多个按键绑定成为Vi Master

海思vi不绑定vpss

海思vi不绑定vpss

image

Vi is a powerful text editor included on most Linux systems. Many people swear by vi and find it faster than any other editor once they’ve learned its key bindings. You can even use vi key bindings in Bash.

Vi是大多数Linux系统中包含的功能强大的文本编辑器。 一旦了解了vi的按键绑定,许多人就会对vi发誓并比其他任何编辑器都更快地找到它。 您甚至可以在Bash中使用vi键绑定。

We’ve already covered getting started with vi for beginners. If you haven’t used vi in a while, you might want to give that post a look to get a refresher on the basics.

我们已经为初学者介绍了vi入门。 如果您有一段时间没有使用vi了,则可能需要看看该文章,以复习基础知识。

模式切换 (Mode Switching)

As a short recap, vi is a modal editor – there’s an insert mode and a standard command mode. In insert mode, vi functions similar to a normal text editor. In command mode, you take advantage of these key bindings.

简短地回顾一下,vi是模式编辑器–有插入模式和标准命令模式。 在插入模式下,vi的功能类似于普通的文本编辑器。 在命令方式下,您可以利用这些键绑定。

  • i – Enter insert mode.

    i –进入插入模式。

  • Escape – Leave insert mode. If you’re already in command mode, Escape does nothing, so you can press Escape to ensure you’re in command mode.

    退出 -退出插入模式。 如果您已经处于命令模式,则Escape不会执行任何操作,因此您可以按Escape以确保您处于命令模式。

image

移动光标 (Moving the Cursor)

Vi uses the hjkl keys to move the cursor in command mode. Early computer systems didn’t always have arrow keys, so these keys were used instead. One advantage of these keyboard shortcuts is that you don’t have to move your fingers from the home row to use them.

Vi使用hjkl键在命令模式下移动光标。 早期的计算机系统并不总是具有箭头键,因此使用了这些键。 这些键盘快捷键的优点之一是,您不必从主行移动手指即可使用它们。

  • h – Move cursor left.

    h –向左移动光标。

  • j – Move cursor down.

    j –向下移动光标。

  • k – Move cursor up.

    k –向上移动光标。

  • l – Move cursor right.

    l –向右移动光标。

You can also use search commands to quickly move the cursor.

您也可以使用搜索命令快速移动光标。

  • / – Type a / followed by some text you want to find and press Enter to quickly move your cursor to the location of the text in the file. For example, if you have the word iguana in your file, type /iguana and press Enter to quickly move the cursor there.

    / –键入/,然后输入要查找的某些文本,然后按Enter键将光标快速移动到文件中文本的位置。 例如,如果文件中包含单词iguana,则键入/ iguana,然后按Enter键将光标快速移到那里。

  • ? – Like /, but searches backwards.

    –类似/,但向后搜索。

  • f – Type an f followed by any character to quickly move the cursor to the next occurrence of the character on the current line. For example, if you have the line “Hello world” on a line and your cursor is at the beginning of the line, type fo to move to the o in Hello. Type fo again to move to the o in world.

    f –键入f,后跟任意字符,以将光标快速移动到当前行上该字符的下一个出现位置。 例如,如果一行上有“ Hello world”行,并且光标在该行的开头,请键入fo移至Hello中的o。 再次键入fo可以移至世界上的o。

  • F – Like f, but searches backwards.

    F –与f类似,但向后搜索。

  • % – Jump between the nearest (), [], or {} characters on the line.

    –在行上最接近的(),[]或{}字符之间跳转。

Use these commands to quickly move to locations in the file:

使用以下命令可以快速移动到文件中的位置:

  • H – Move cursor to highest (top) line in file.

    H –将光标移动到文件的最高(顶部)行。

  • M – Move cursor to middle line in file.

    M –将光标移到文件的中间行。

  • L – Move cursor to lowest (bottom) line in file.

    L –将光标移动到文件的最低(底部)行。

  • #G – Type a number and then type G to go to that line in the file. For example, type 4G and press Enter to move to the fourth line in the file.

    #G –键入数字,然后键入G以转到文件中的该行。 例如,键入4G并按Enter键以移至文件的第四行。

Moving between words:

在单词之间移动:

  • w – Move forward a word.

    w –向前移动一个单词。

  • #w – Move forward a number of words. For example, 2w moves forward two words.

    #w –向前移动多个单词。 例如,2w向前移动两个单词。

  • b – Move back a word.

    b –后退一个单词。

  • #b – Move back a number of words. For example, 3b moves back three words.

    #b –后退一些单词。 例如,3b向后移三个单词。

  • e – Move to end of the current word.

    e –移至当前单词的末尾。

image

复制和粘贴 (Copying & Pasting)

Vi refers to the act of copying as “yanking.”

Vi将复制行为称为“拖拉”。

  • v – Press v and move the cursor to select a section of text.

    v –按v并移动光标以选择文本的一部分。

  • y – Copy (yank) the selected text.

    y –复制(添加)所选文本。

  • p – Paste at cursor.

    p –粘贴到光标处。

  • x – Cuts the selected text. Cuts the character under the cursor if no text is selected

    x –剪切选定的文本。 如果未选择任何文本,则剪切光标下的字符

  • r – Type r and then type another character to replace the character under the cursor.

    r –键入r,然后键入另一个字符以替换光标下的字符。

组合命令 (Combining Commands)

Some commands – including the y and v commands above and the d (delete) command accept cursor motion commands.

某些命令(包括上面的y和v命令以及d(删除)命令)接受光标移动命令。

For example, when you press d to delete some text, nothing will happen until you enter a cursor motion command. For example:

例如,当您按d删除某些文本时,在您输入光标移动命令之前不会发生任何事情。 例如:

  • dw – Deletes the next word.

    dw –删除下一个单词。

  • db – Deletes the previous word

    db –删除前一个单词

  • de – Deletes to the end of the current word.

    de –删除到当前单词的末尾。

  • dL – Deletes all text below the cursor in the file.

    dL –删除文件中光标下方的所有文本。

  • d/unicorn – After pressing Enter, deletes all text between the cursor and the word “unicorn” in the current file.

    d / unicorn –按下Enter键后,删除当前文件中光标和单词“ unicorn”之间的所有文本。

  • dd – Deletes an entire line.

    dd –删除整行。

As you can see, the combination of combining a command with a cursor movement command is very powerful.

如您所见,将命令与光标移动命令结合起来的功能非常强大。

image

重复并撤消 (Repeat & Undo)

Vi’s repeat command is very powerful, as it can repeat complex, combined commands.

Vi的repeat命令非常强大,因为它可以重复复杂的组合命令。

  • u – Undo.

    u –撤消。

  • . – The . repeats the last full command.  The insert command also functions as a command here. For example, type iunicorn and press Escape. You can then use the . key to insert the word unicorn at the cursor.

    –。 重复上一个完整的命令。 插入命令在这里也用作命令。 例如,键入iunicorn,然后按Escape键。 然后,您可以使用。 键在光标处插入独角兽一词。

奖励:在Bash中使用Vi键绑定 (Bonus: Using Vi Key Bindings in Bash)

Once you’ve mastered the vi key bindings, you may want to use them elsewhere on your system. No problem – you can set the Bash shell to use vi-style key bindings.

掌握了vi键绑定后,您可能希望在系统的其他位置使用它们。 没问题–您可以将Bash shell设置为使用vi样式的键绑定。

Try this out in the current session by running the following command in a Bash terminal:

通过在Bash终端中运行以下命令,在当前会话中尝试此操作:

set -o vi

设置-o vi

Bash will start in insert mode – press Escape to enter command mode and use these key bindings.

Bash将以插入模式开始-按Escape进入命令模式并使用这些键绑定。

If you like this, you can add the command to your ~/.bashrc file and it will be automatically run each time you log in. Use the vi .bashrc command to open and edit the file in vi.

如果愿意,可以将命令添加到〜/ .bashrc文件中,每次登录时该命令都会自动运行。使用vi .bashrc命令在vi中打开和编辑该文件。

image


This isn’t a complete list of key bindings for vi, but it should help you flex your vi wings and learn to fly. This list of key bindings at Harvard’s website is more complete and has more information, although it’s less organized and harder to digest all at once.

这不是vi的键绑定的完整列表,但是它应该可以帮助您灵活使用vi并学习飞行。 哈佛网站上的键绑定列表更完整,并且具有更多信息,尽管它的组织性较差并且一次很难消化。

翻译自: https://www.howtogeek.com/115051/become-a-vi-master-by-learning-these-30-key-bindings/

海思vi不绑定vpss

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值