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? 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设置? 无需挂载或执行一些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。 它是一个较旧的版本(〜1.7),但对于本教程来说确实无关紧要。 如果要首先在Mac上升级VIM,请在终端中执行以下步骤(需要homebrew ):

brew install mercurial
sudo mkdir -p /opt/local/bin
cd ~
hg clone https://code.google.com/p/vim/
cd vim
./configure --prefix=/opt/local
make
sudo make install
echo 'PATH=/opt/local/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile

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,只需在您的终端上运行:

sudo apt-get install vim

For CentOS, just run:

对于CentOS,只需运行:

sudo yum install vim

测试您的安装 (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 -v

Vim Startup Screen

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

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

:q!

超级基础入门 (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对其进行编辑:

vim whatever.txt

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

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

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:

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

i

Insert mode with 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 ESC.

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

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)。

:wq

Saving a file with Vim

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

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

:q!

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还带有自己的教程 。 如果您需要提高自己的技能,只需在命令行中输入以下内容即可:

vimtutor

Vimtutor Screenshot

移动光标 (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:

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

  • h - Left

    h
  • k - Up

    k向上
  • l - Right

    l
  • j - Down

    j

Here's a visual for reference:

这是供参考的视觉效果:

^
      k
< h       l >
      j
      v

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 git pull and I couldn't even figure out how to exit until a friend helped me out.

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

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

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

:q

To quit and discard changes, type:

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

:q!

To quit and save changes, type:

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

:wq

文字编辑-删除 (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 ESC to enter Command Mode. Next, navigate to any letter you want to delete and hit:

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

x

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.

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

i

追加中 (Appending)

This puts the cursor after the current position.

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

a

打开命令 (Open Commands)

This puts the cursor below the line:

这会将光标置于行下方

o

And this puts the cursor above the line:

这会将光标置于行上方

O

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命令将如下所示:

[OPERATOR][NUMBER][MOTION]

经营者 (Operators)

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

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

Here's a list of common operators:

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

  • d - Delete (acts like a "cut" command though)

    d删除(虽然类似于“剪切”命令)
  • c - Change

    c变更
  • y - Yank

    y扬克
  • p - Insert last deleted text after cursor (put command)

    p在光标之后插入最后删除的文本(put命令)
  • r - Replace

    r替换

动作 (Motions)

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

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

Here's a list of common motions:

以下是一些常见的动作:

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

    w -直到下一个单词的开头, 不包括其第一个字符。
  • e - To the end of the current word, INCLUDING the last character.

    e到当前单词的末尾, 包括最后一个字符。
  • $ - To the end of the line, INCLUDING the last character.

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

And some additional others:

以及其他一些:

  • w - Forward by word

    w按词转发
  • b - Backward by word

    b按字向后
  • ) - Beginning of next sentence

    ) -下一个句子的开头
  • ( - Beginning of current sentence

    ( -当前句子的开头
  • } - Beginning of next paragraph

    } -下一段的开始
  • { - Beginning of current paragraph

    { -当前段落的开头
  • ] - Beggining of next sect

    ] -开始下一个教派
  • [ - Begginning of current section

    [ -本节开始
  • H - Top line of screen

    H屏幕顶部
  • L - Last line of screen

    L屏幕的最后一行

计数 (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:

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

dw
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());

删除到行尾 (Deleting to End of a Line)

This will delete everything until the end of the line. Move your cursor to the beginning of a line and enter this command:

这将删除所有内容,直到该行的末尾。 将光标移至行首,然后输入以下命令:

d$

Now, here's an example of a count. This will run the command twice and deleting two lines after the cursor position.

现在,这是一个计数示例。 这将运行两次命令,并删除光标位置后的两行。

d2$
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());

Deleting a line is a super common task. Vim has a shortcut built in for this. For example, to quickly delete a line you can always just do dd instead.

删除行是一项超常见的任务。 Vim有一个内置的快捷方式。 例如,要快速删除一行,您始终可以只用dd代替。

删除四个词 (Deleting Four Words)

Here's a command for deleting four words:

这是删除四个单词的命令:

d4w
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());

撤消命令 (The Undo Command)

With all these commands, there's a good chance you might mess up once or twice. This is totally normal and okay. You can quickly undo a command with:

使用所有这些命令,您很有可能会弄乱一两次。 这是完全正常的,还可以。 您可以使用以下命令快速撤消命令:

u

Try undoing some commands in the editor below to see how easy it is:

尝试在下面的编辑器中撤消一些命令,以查看它是多么容易:

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());

快速页面导航 (Quick Page Navigation)

Scrolling doesn't really exist in a terminal. So if you have a long file that you're editing, it might get real boring navigating with the arrow keys or h, k, l, j. Here's some tips for this:

终端中根本不存在滚动功能。 因此,如果您要编辑的文件很长,使用箭头键或h, k, l, j导航可能会很无聊。 这里有一些提示:

移至文件底部 (Move to the bottom of a file)

:G

移至文件开头 (Move to the start of a file)

:gg

导航到特定行 (Navigate to a specific line)

You can view your current page line with:

您可以使用以下方法查看当前的页面行:

:ctrl+g

You can jump to a specific line with:

您可以使用以下方法跳转到特定行:

:123+G

正在搜寻 (Searching)

You're probably used to doing ctrl-f to jump around a page. Vim is actually really similar to this - except it's a command. You're probably learning by now that everything is a command action.

您可能习惯于使用ctrl-f在页面上跳转。 Vim实际上确实与此类似- 只是命令 。 您现在可能已经知道,一切都是命令操作。

在光标位置之后搜索页面 (Search a page after the cursor position)

:/cats

在光标位置之前搜索页面 (Search a page before the cursor position)

:?dogs

转到下一场或上一场比赛 (Go to next or previous match)

To navigate to the next search match, enter:

要导航到下一个搜索匹配项,请输入:

n

To navigate to the previous search match, enter:

要导航到上一个搜索匹配项,请输入:

N

Try it out:

试试看:

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());

匹配搜索 (Matching Search)

By this point, you can jump around the page and search things, but it's still slow to locate various things in a file. In Vim, you can jump around based on opening and closing matching brackets.

至此,您可以在页面上跳转并搜索内容,但是在文件中查找各种内容仍然很慢。 在Vim中,您可以基于打开和关闭匹配的括号来跳转。

For example, say you have:

例如,假设您有:

function hippopotamus() {
    // insert 1 million lines of code here
}

If you go navigate to { and hit the following key, you'll jump to it's matching counter part.

如果您导航到{并按以下键,则将跳至其匹配的计数器部分。

%

This is insanely useful for quickly jumping around functions. This works on the following:

这对于快速跳转功能非常有用。 这适用于以下情况:

  • ( and )

    (和)
  • [ and ]

    [和]
  • { and }

    {和}

Try it in the example below, it's awesome:

在下面的示例中尝试一下,它很棒:

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());

搜索和替换 (Search and Replace)

Searching and jumping around the page is one thing, but maybe you want to change all words of cat to the word dog. This is really easy with Vim.

搜索和跳转页面是一回事,但是也许您想将cat所有单词更改为dog 。 使用Vim真的很容易。

查找和替换 (Find and Replace)

:s/cat/dog

查找并替换所有 (Find and Replace All)

To replace all instances, you need to make the find and replace global. Here's how:

要替换所有实例,您需要进行全局查找和替换。 这是如何做:

:s/cat/dog/g

This can get infinitely more complex. You can do regular expression find and replaces, replace only on certain lines, sections, and more.

这会变得更加复杂。 您可以进行正则表达式查找和替换,仅在某些行部分等上进行替换。

执行外部命令 (Execute an External Command)

This creeps right out of the area of getting started with Vim to the intermediate parts of it. With Vim, the commands aren't just limited to the Vim syntax/language of operators and motions.

这从Vim的入门领域一直延伸到中间部分。 使用Vim,命令不仅限于Vim语法/运算符和动作的语言。

You can execute external commands as you normally would from the command line inside of the editor. All you need to do is start the command with an exclamation mark.

您可以像通常从编辑器内部的命令行一样执行外部命令。 您需要做的只是用感叹号启动命令。

Here's an example to list all files:

这是列出所有文件的示例:

:!ls -al

As you learn more about Vim, you'll see how insanely powerful this will be. You can do things like write to other files, grab code from other files, paste into other files, and more. In a sense, it like your own little Sublime Sidebar on steroids. We won't cover any of this in this tutorial, but here's a good resource for learning more about external commands with Vim.

当您了解有关Vim的更多信息时,您会发现它有多么强大。 您可以执行诸如写入其他文件,从其他文件获取代码,粘贴到其他文件等操作。 从某种意义上讲,它就像您自己的类固醇Sublime侧边栏。 在本教程中,我们不会涉及任何内容,但是这里是一个很好的资源,可用于通过Vim了解更多有关外部命令的信息

配置Vim (Configuring Vim)

Vim can also do things like syntax highlighting. By default, this usually isn't enabled. To enable it on a file, simply enter the following command:

Vim还可以执行诸如语法突出显示之类的操作。 默认情况下,通常不启用此功能。 要在文件上启用它,只需输入以下命令:

:syntax on

This is quite annoying to have to reenter on each file. This is where configuring Vim comes in handy. All Vim installs come with a file in your home directory called .vimrc. If it's not there, create one.

必须在每个文件上重新输入,这很烦人。 这是配置Vim的方便之处。 所有Vim安装都在您的主目录中带有一个名为.vimrc的文件。 如果不存在,请创建一个。

So, from the command line and with vim, let's force enable :syntax on to be a default setting. The first step is to open the file in Vim:

因此,从命令行并使用vim,让我们强制启用:syntax on为默认设置。 第一步是在Vim中打开文件:

vim ~/.vimrc

Then simply add this line to the file:

然后只需将以下行添加到文件中:

syntax on

Finally, save the file to have syntax on by default in Vim:

最后,保存文件以在Vim中默认启用语法:

:wq

There's a ton of these features. Things like showing a ruler, always showing the line number, themes and color schemes, and much more. You can even create short codes and functions to operate from.

这些功能很多。 比如显示标尺 ,总是显示行号主题和配色方案等。 您甚至可以创建短代码和函数以进行操作。

A good reference for this is The Ultimate Vim Configuration for .vimrc. You can either copy this or pick and choose all the goodies you want from it.

一个很好的参考是.vimrc的Ultimate Vim配置 。 您可以复制它,也可以从中选择所有想要的东西。

有用的技巧和窍门 (Useful Tips and Tricks)

You should now be comfortable with Vim on the command line. Here's some miscellaneous useful tips and tricks.

现在,您应该可以在命令行上使用Vim了。 这是一些其他有用的提示和技巧。

将Vim设置为默认命令行编辑器 (Set Vim as your default command line editor)

Nano is usually a default command line editor in a lot of systems. On Ubuntu or other Debian-based systems, run this command to make the switch:

在许多系统中,Nano通常是默认的命令行编辑器。 在Ubuntu或其他基于Debian的系统上,运行以下命令进行切换:

sudo update-alternatives --config editor

将Vim设置为Git的默认编辑器 (Set Vim as your default editor for Git)

git config --global core.editor "vim"

外挂程式 (Plugins)

Vim also has the ability to allow third-parties to write plugins into the editor. This is awesome because you can use all this pre-built additional functionality by others.

Vim还具有允许第三方将插件写入编辑器的功能。 这很棒,因为其他人可以使用所有这些预先构建的附加功能。

For example, NERD Tree will essentially simulate a sidebar for your editor.

例如, NERD Tree本质上将为您的编辑器模拟一个侧边栏。

NERD Tree Screenshot for Wim

To learn more about plugins, check out these additional resources:

要了解有关插件的更多信息,请查看以下其他资源:

新病毒 (Neovim)

Appararently building a plugins on Vim is pretty difficult to do though. Neovim is a rebuild of Vim to hopefully making adding plugins easier. You can check out their official website to learn more.

尽管在Vim上相应地构建插件是非常困难的。 Neovim是对Vim的重新构建,希望可以使添加插件更加容易。 您可以查看他们的官方网站以了解更多信息。

On Ubuntu, you can install Neovim by doing:

在Ubuntu上,您可以执行以下步骤安装Neovim:

sudo add-apt-repository ppa:neovim-ppa/unstable
sudo apt-get update
sudo apt-get install neovim

结论 (Conclusion)

That's all there is to getting started with Vim. Just like anything else in the development world, you get better at it by just doing it. Hopefully by now, you're ready to start editing files with Vim.

这就是Vim入门的全部。 就像开发世界中的任何其他事物一样,您只要做到这一点就能变得更好。 希望现在,您已经准备好开始使用Vim编辑文件。

Finally, there's a ton of awesome content on the web for Vim resources and learning beyond this article. I definitely encourage you to check them out:

最后,在Web上有大量关于Vim资源的很棒的内容,以及本文以外的知识。 我绝对鼓励您检查一下:

翻译自: https://scotch.io/tutorials/getting-started-with-vim-an-interactive-guide

vim交互软件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值