vim交互软件_Vim入门:交互式指南

vim交互软件

Command line editors can be a scary thing to learn and use for beginners, and Vim is probably the scariest of them all – but it doesn’t have to be. There’s a lot to cover in Vim (more than one tutorial can possibly teach), but we’ll cover most of the basics here so that you’ll be at least comfortable editing files with it.

对于初学者来说,命令行编辑器是一件令人恐惧的学习和使用的事情,而Vim可能是所有人中最可怕的- 但并非必须如此 。 Vim有很多内容(可能不止一个教程可以教),但是我们将在这里介绍大多数基础知识,以便您至少可以轻松地使用它来编辑文件。

We’re going to break this tutorial into two sections. A super basic starter to get you up and running and then more detailed sections below with a better explanation

我们将本教程分为两个部分。 一个超级基本的入门工具,可帮助您入门和运行,然后在下面进行更详细的介绍并提供更好的说明

Here’s a blank canvas of what editing with Vim is like in our interactive tutorial. All examples will be JavaScript files. Try it out:

这是一张空白的画布,显示了在我们的交互式教程中,用Vim进行编辑的过程。 所有示例均为JavaScript文件。 试试看:

function meow() { return ‘meow’; } function bark() { return ‘woof’; } function getRandomAnimal() { var animals = [ ‘cat’, ‘dog’, ‘hippo’, ‘lion’, ‘bear’, ‘zebra’ ]; return animals[Math.floor(Math.random()*animals.length)]; } console.log(meow()); console.log(bark()); console.log(getRandomAnimal()); 函数meow(){return’meow’; } function bark(){return’woof’; }函数getRandomAnimal(){var animals = [‘cat’,’dog’,’hippo’,’lion’,’bear’,’zebra’]; 返回动物[Math.floor(Math.random()* animals.length)]; } console.log(meow()); console.log(bark()); console.log(getRandomAnimal());

介绍 (Introduction)

Command line editors are exactly what they sound like, they give you the ability to edit files from the command line. There’s a whole bunch of them, too:

命令行编辑器听起来确实不错,它们使您能够从命令行编辑文件 。 也有一大堆:

  • Pico

    微微

  • Nano

    奈米

  • Emacs

    埃马克斯

  • Vi

  • Vim

    Vim

  • Neovim

    新病毒

Nano (which is basically a clone of Pico) is probably the most common one. It’s just a dead simple editor and most people can usually figure out how to use it by just opening it up. Vim on the other hand requires training. Vim is a clone of Vi but improved (Vi IMproved). It has all the functionality of Vi and more – things like extra features, plugins, and more.

Nano(基本上是Pico的克隆)可能是最常见的一种。 它只是一个简陋的简单编辑器,大多数人通常都可以通过打开它来弄清楚如何使用它。 另一方面,Vim需要培训。 Vim是Vi的克隆,但经过改进( Vi IMproved )。 它具有Vi的所有功能及更多功能-诸如其他功能,插件等。

Vim is also extremely extensible. You can use it as your primary editor or just as a simple editor for changing files when SSH’d into a server (usually what I just do). The goal of this tutorial is going to be to get you comfortable enough to make edits on a server with Vim. At the end of this tutorial you’ll be able to make edits to config files, use Vim to manage your Git merges and conflicts, and more. How much you want to use it is up to you.

Vim也非常可扩展。 您可以将它用作您的主编辑器,也可以将其用作简单的编辑器,以便在SSH进入服务器时更改文件(通常是我所做的)。 本教程的目的是使您足够舒适,以便在使用Vim的服务器上进行编辑。 在本教程的最后,您将能够对配置文件进行编辑,使用Vim管理您的Git合并和冲突,以及更多。 您要使用多少取决于您。

If you’re able to confidently use a vanilla install of Vim, you can effectively make edits on any server or OS worry free. Need to change an Nginx or Apache setting/strong> No need to mount or do some FTP/SFTP stuff. Simply SSH into the box and make it happen from the command line in seconds.

如果您可以放心地使用原始安装的Vim,则可以有效地在任何服务器或操作系统上进行编辑,而无需担心。 是否需要更改Nginx或Apache设置/strong> 无需挂载或执行一些FTP / SFTP任务。 只需通过SSH进入框中,即可在几秒钟内从命令行进行操作。

Learning Vim is an investment. As you learn it, you’ll only get better with it and find more and more things to improve your productivity. Very good people with it will claim it’s like an extension of your fingers allowing you to edit files faster and smarter than you can even with an editor as awesome as Sublime Text.

学习Vim是一项投资。 当您学习它时,您只会对此感到更好,并发现越来越多的东西可以提高您的生产率。 很好的人会声称它就像是手指伸展,使您可以比使用Sublime Text出色的编辑器更快,更智能地编辑文件。

安装Vim (Installing Vim)

Vim works in almost any OS environment – including Windows. You can expect to be able to use it on virtually any machine or system that you’re working with.

Vim几乎可以在任何操作系统环境(包括Windows)中运行。 您可以期望几乎可以在所使用的任何计算机或系统上使用它。

Mac电脑 (Macs)

If you’re using a Mac, VIM is already installed. It’s an older version (~1.7), but it really doesn’t matter for this tutorial. If you want to upgrade VIM on mac first, follow these steps (requires homebrew) in your terminal:

如果您使用的是Mac,则已经安装了VIM。 它是一个较旧的版本(.7),但对于本教程来说确实无关紧要。 如果要首先在Mac上升级VIM,请在终端中执行以下步骤(需要homebrew ):

After you do this, you should have VIM version (7.x) on your machine.

完成此操作后,您的计算机上应具有VIM版本(7.x)。

视窗 (Windows)

For Windows users visit the Official Vim website to download.

对于Windows用户,请访问Vim官方网站进行下载。

的Linux (Linux)

Vim ships as a package for *nix systems.

Vim作为* nix系统的软件包提供。

For Ubuntu, just run this from your terminal:

对于Ubuntu,只需在您的终端上运行:

For CentOS, just run:

对于CentOS,只需运行:

测试您的安装 (Test Your Install)

Now that you have installed (or updated) Vim, it’s time to test to see if it worked. From the command line in your terminal, type:

现在您已经安装(或更新)了Vim,是时候测试一下它是否有效了。 在终端的命令行中,输入:

vim交互软件_Vim入门:交互式指南

That’s it! Now to exit this screen, just type:

而已! 现在要退出此屏幕,只需键入:

超级基础入门 (Super Basic Starter)

Before we go into detail, let’s do a super basic starter example to get things rolling.

在详细介绍之前,让我们做一个超级基本的入门示例,以使事情进展顺利。

From the terminal, navigate to a file and let’s edit it with Vim:

在终端上,导航到一个文件,然后使用Vim对其进行编辑:

Alternatively, you can create a brand new file with the same command: .

另外,您可以使用相同的命令创建一个全新的文件: 。

Now that you’re using Vim, we need to explain the two modes that Vim has: Command Mode and Insert Mode. Command Mode, just like it sounds, is for executing commands. Things like custom Vim commands (we’ll cover later), saving files, etc. Insert Mode, also just like it sounds, is for editing text freely.

现在您正在使用Vim,我们需要解释Vim的两种模式: Command ModeInsert Mode 。 就像听起来一样,命令模式用于执行命令。 诸如自定义Vim命令(我们将在后面介绍),保存文件等操作。插入模式(听起来也一样)可用于自由编辑文本。

To enter Insert Mode simply type:

要进入插入模式,只需键入:

vim交互软件_Vim入门:交互式指南

Now type any nonsense you’d like. Once you’re done, let’s save the file. You need to first exit Insert Mode and enter Command Mode by hitting .

现在输入您想要的任何废话。 完成后,让我们保存文件。 您需要先退出插入模式,然后按进入命令模式。

Once you’re back into command mode, you’ll need to save the file (called a Write) and then quit Vim. To enter a command, you need to hit the semicolon key . Here’s the command to save the edits (write, quit).

返回命令模式后,需要保存文件(称为Write),然后退出Vim。 要输入命令,您需要按分号 。 这里的命令保存编辑(W仪式,Q UIT)。

vim交互软件_Vim入门:交互式指南

That’s it! Alternatively, if you want to quit Vim without saving changes, just type:

而已! 另外,如果要退出Vim而不保存更改,只需键入:

The exclamation mark means discard changes. So this literally will translate to “quit and discard changes” for Vim.

感叹号表示放弃更改。 因此,这从字面上将转化为“Q UIT和丢弃改变” Vim的。

That’s all there is to the basic starter. If you want, you can either follow along in your own terminal or use our interactive editors below for the more detailed tutorial.

这就是基本入门的全部内容。 如果需要,您可以在自己的终端机中继续学习,也可以使用下面的交互式编辑器获取更详细的教程。

学习讲Vim的语言 (Learn to Speak Vim’s Language)

Vim is always just listening for instructions from you. It’s up to you to give it commands. You need to tell the editor what to do. Vim follows a system for the syntax and pattern of these commands. Once you learn the “language” of Vim, all you need to do is keep learning more commands – Vim’s “vocabulary”.

Vim始终只是在听您的指示。 由您决定给它命令。 您需要告诉编辑者该怎么做。 Vim遵循这些命令的语法和模式的系统。 学习了Vim的“语言”后,您需要做的就是继续学习更多命令-Vim的“词汇表”。

There’s no way to cover all the commands, but we’ll get you started with the most common ones and how to start using them. In time, you’ll learn more and more of these. Eventually, just when you think you’ve become a Vim expert, BOOM, you’ll learn a new command and trick to save you time.

没有涵盖所有命令的方法,但是我们将带您开始最常用的命令以及如何开始使用它们。 随着时间的流逝,您将学到更多。 最终,当您以为自己成为Vim专家BOOM时 ,就会学习新的命令和技巧以节省时间。

Vim also comes with its own tutorial. If you need to freshen up on your skills, you can simply type this from the command line to bring it up:

Vim还带有自己的教程 。 如果您需要提高自己的技能,只需在命令行中输入以下内容即可:

vim交互软件_Vim入门:交互式指南

移动光标 (Moving the Cursor)

From the earlier example, you were probably using the arrow keys to navigate around. That’s perfectly okay, but it’s recommended that you navigate a different way and actually not with the arrow keys. This way may be unnatural or weird at first, but it’s recommended to use these keys instead:

在前面的示例中,您可能使用了箭头键来浏览。 完全可以,但是建议您以其他方式导航,而实际上不要使用箭头键 。 这种方法一开始可能不自然或很奇怪,但是建议改用以下这些键:

  • – Left

  • – Up

    向上

  • – Right

  • – Down

Here’s a visual for reference:

这是供参考的视觉效果:

Simply try navigating around with these keys below to get the hang of it. It will get easier in time. You can hold any of these keys to quickly make the action repeat:

只需尝试使用下面的这些键来浏览,即可使用它。 它将变得更容易及时。 您可以按住以下任意键以快速重复操作:

function meow() { return ‘meow’; } function bark() { return ‘woof’; } function getRandomAnimal() { var animals = [ ‘cat’, ‘dog’, ‘hippo’, ‘lion’, ‘bear’, ‘zebra’ ]; return animals[Math.floor(Math.random()*animals.length)]; } console.log(meow()); console.log(bark()); console.log(getRandomAnimal()); 函数meow(){return’meow’; } function bark(){return’woof’; }函数getRandomAnimal(){var animals = [‘cat’,’dog’,’hippo’,’lion’,’bear’,’zebra’]; 返回动物[Math.floor(Math.random()* animals.length)]; } console.log(meow()); console.log(bark()); console.log(getRandomAnimal());

退出Vim (Exiting Vim)

The first time I encountered Vim I had no idea what it was. A server had it pop-open on me with a and I couldn’t even figure out how to exit until a friend helped me out.

第一次遇到Vim时,我不知道它是什么。 服务器通过在我身上弹出它,我什至不知道如何退出,直到一个朋友帮助我。

To quit, enter Command Mode with , then just type:

要退出,请使用进入“命令模式”,然后键入:

To quit and discard changes, type:

要退出并放弃更改,请键入:

To quit and save changes, type:

要退出并保存更改,请键入:

文字编辑-删除 (Text Editing – Deletion)

It’s one thing to delete text from Insert Mode, but you can also delete text from Command Mode. In the example below, click the editor and hit to enter Command Mode. Next, navigate to any letter you want to delete and hit:

从插入模式删除文本是一回事,但是您也可以从命令模式删除文本。 在下面的示例中,单击编辑器,然后按进入命令模式。 接下来,导航至您要删除并点击的任何字母:

Try it below:

在下面尝试:

function meow() { return ‘meow’; } function bark() { return ‘woof’; } function getRandomAnimal() { var animals = [ ‘cat’, ‘dog’, ‘hippo’, ‘lion’, ‘bear’, ‘zebra’ ]; return animals[Math.floor(Math.random()*animals.length)]; } console.log(meow()); console.log(bark()); console.log(getRandomAnimal()); 函数meow(){return’meow’; } function bark(){return’woof’; }函数getRandomAnimal(){var animals = [‘cat’,’dog’,’hippo’,’lion’,’bear’,’zebra’]; 返回动物[Math.floor(Math.random()* animals.length)]; } console.log(meow()); console.log(bark()); console.log(getRandomAnimal());

You’re probably wondering why you just won’t enter Insert Mode to delete characters. You can always do that, but you’ll see from future examples that deleting text from Command Mode is more powerful and much quicker. It’s better to start the habit now.

您可能想知道为什么不进入插入模式来删除字符。 您可以始终这样做,但是从以后的示例中您会看到,从“命令模式”中删除文本更强大,更快捷。 最好现在就养成习惯。

文字编辑-插入 (Text Editing – Insertion)

Text editing simply requires you that you enter Insert Mode. We already covered how to do that, but there’s some other methods to do this that can help speed things up and save you some keystrokes.

文本编辑仅要求您进入插入模式。 我们已经介绍了如何执行此操作,但是还有其他一些方法可以帮助您加快操作速度并节省一些击键。

插入 (Inserting)

This puts the cursor before the current position.

这会将光标置于当前位置之前

追加中 (Appending)

This puts the cursor after the current position.

这会将光标置于当前位置之后

打开命令 (Open Commands)

This puts the cursor below the line:

这会将光标置于行下方

And this puts the cursor above the line:

这会将光标置于行上方

Try each these below to see the differences in action:

请尝试以下每种方法,以查看操作上的差异:

function meow() { return ‘meow’; } function bark() { return ‘woof’; } function getRandomAnimal() { var animals = [ ‘cat’, ‘dog’, ‘hippo’, ‘lion’, ‘bear’, ‘zebra’ ]; return animals[Math.floor(Math.random()*animals.length)]; } console.log(meow()); console.log(bark()); console.log(getRandomAnimal()); 函数meow(){return’meow’; } function bark(){return’woof’; }函数getRandomAnimal(){var animals = [‘cat’,’dog’,’hippo’,’lion’,’bear’,’zebra’]; 返回动物[Math.floor(Math.random()* animals.length)]; } console.log(meow()); console.log(bark()); console.log(getRandomAnimal());

运算符以及动作,计数和它们的组合 (Operators and Motions, Counts, and Combining Them)

Commands are where the true power and efficiency come from Vim. It takes time to start using them, but they all follow a similar pattern. It’s a good idea to learn how commands work, not memorize commands. Commands are broken down into these parts:

命令是Vim真正的功能和效率所在。 开始使用它们需要花费时间,但是它们都遵循类似的模式。 学习命令的工作方式而不是记住命令是个好主意。 命令分为以下几部分:

  • Operator

    操作员

  • Numbers

    号码

  • Motions

    动作

When to put together, the Vim Command will look something like this:

当放在一起时,Vim命令将如下所示:

经营者 (Operators)

Operators are actions. These are like verbs of a sentence when “speaking Vim”.

操作员就是行动。 这些就像“说Vim”时句子的动词

Here’s a list of common operators:

以下是常用运算符的列表:

  • – Delete (acts like a “cut” command though)

    删除(虽然类似于“剪切”命令)

  • – Change

    变更

  • – Yank

    扬克

  • – Insert last deleted text after cursor (put command)

    在光标之后插入最后删除的文本(put命令)

  • – Replace

    替换

动作 (Motions)

Motions provide context to your Operators. These execute the action in a particular way.

动作为操作员提供了背景信息 。 它们以特定方式执行动作。

Here’s a list of common motions:

以下是一些常见的动作:

  • – Until the start of the next word, EXCLUDING its first character.

    -直到下一个单词的开头, 不包括其第一个字符。

  • – To the end of the current word, INCLUDING the last character.

    到当前单词的末尾, 包括最后一个字符。

  • – To the end of the line, INCLUDING the last character.

    -至行尾, 包括最后一个字符。

And some additional others:

以及其他一些:

  • – Forward by word

    按词转发

  • – Backward by word

    按字向后

  • – Beginning of next sentence

    -下一个句子的开头

  • – Beginning of current sentence

    -当前句子的开头

  • – Beginning of next paragraph

    -下一段的开始

  • – Beginning of current paragraph

    -当前段落的开头

  • – Beggining of next sect

    -开始下一个教派

  • – Begginning of current section

    -本节开始

  • – Top line of screen

    屏幕顶部

  • – Last line of screen

    屏幕的最后一行

计数 (Counts)

Counts are optional and simply let you put a multiplier to your command and motion. You’ll see how these work in the examples below.

计数是可选的,只需让您在命令和动作上增加一个乘数即可。 您将在下面的示例中看到它们的工作方式。

In time you’ll learn more and more of these and get quicker and quicker. It’s usually handy to have a solid Vim Cheat Sheet on hand when getting started.

随着时间的流逝,您将学到越来越多的知识,并且越来越快。 开始时,手头有一个坚实的Vim作弊表通常很方便。

Let’s go over some examples to demo how these work to together. Once you recognize that it’s a pattern and language, you can start figuring out and testing these all on your own.

让我们来看一些示例,以演示它们如何协同工作。 一旦认识到它是一种模式和语言,就可以自己找出并测试所有这些。

删除一个字 (Deleting a Word)

Navigate to beginning of the word in the editor below and enter this command. If you’re in the middle it will stop at where the word ends:

在下面的编辑器中导航到单词的开头,然后输入此命令。 如果您在中间,它将在单词结尾处停止:

function meow() { re

来源:culiu9261

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年6月16日
下一篇 2020年6月16日

相关推荐