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.
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:
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.
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.
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.
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 (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,是时候测试一下它是否有效了。 在终端的命令行中,输入:
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:
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.
To enter Insert Mode simply type:
要进入插入模式,只需键入:
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).
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”.
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还带有自己的教程 。 如果您需要提高自己的技能,只需在命令行中输入以下内容即可:
移动光标 (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:
要退出并保存更改,请键入:
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 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
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!