vim block vim

精选最流行的命令以及如何使用它们 (A curation of the most popular commands and how to use them)

If you’ve ever used Vim, you know how difficult it can get to reach the same speed as in a “normal” GUI editor. But once you do, the payoff is exponential — you get much more efficient at writing code. Of course, this isn’t the main reason for this post.

如果您曾经使用过Vim,那么您将知道达到与“常规” GUI编辑器相同的速度是多么困难。 但是,一旦这样做,收益是成倍的—您可以更高效地编写代码。 当然,这不是这篇文章的主要原因。

The majority of the time goes — or should go — into designing a solution to your problem, not actually coding it; so optimizing the how-fast-you-code bit seems like the last thing to focus on. It’s not a leverage point.

大多数时间(或应该去)用于设计问题的解决方案,而不是实际编码。 因此优化您的编码速度似乎是最后要关注的事情。 这不是一个杠杆点。

This post took shape because of another reason: the non-existence of GUIs on SSH’ed machines. What are you going to do now? Any machine where you have access to the terminal and you want to edit a file — You have 2 options:

这篇文章之所以成形,是由于另一个原因:SSH计算机上不存在GUI。 你现在要做什么? 您可以访问终端并要编辑文件的任何计算机-您有2个选项:

  1. Give up, try to close Vim放弃,尝试关闭Vim
  2. Master VimVim大师

Just making a copy of vimtutor wouldn’t help anyone. So here I’m using a different approach: I aggregated the best bits of vim that I use in everyday life as a software developer, along with mnemonics to remember the stuff by. This contains almost everything you need for regular editing and writing.

仅仅复制一份vimtutor并不会帮助任何人。 因此,在这里我使用了另一种方法:我汇总了作为软件开发人员在日常生活中使用的vim的最佳片段,以及用于记忆这些东西的助记符。 它包含了常规编辑和编写所需的几乎所有内容。

基础 (The basics)

Stick with me, this isn’t about the commands but the ideology behind them!

坚持我,这与命令无关,而是其背后的意识形态!

模式 (Modes)

Vim has 2 modes:

Vim有2种模式:

  • Normal ( Command mode)普通(命令模式)
  • Insert ( Edit mode )插入(编辑模式)

When you open Vim, you start in normal mode. To enter back into normal mode at anytime, press the ESC key. Normal mode is where you can issue commands: the list of commands is endless!

打开Vim时,将以普通模式启动。 要随时返回正常模式,请按ESC键。 在普通模式下,您可以发出命令:命令列表无穷无尽!

There are a lot of ways to enter insert mode. The most intuitive one is to use the i command. i for insert. In normal mode, press i and you’ll enter insert mode. Now anything you type will show up in the editor. One of the biggest hurdles, sorted.

有很多方法可以进入插入模式。 最直观的一种是使用i命令。 i要插入。 在普通模式下,按i ,您将进入插入模式。 现在,您键入的任何内容都会显示在编辑器中。 最大的障碍之一,排序。

The mental model — to understand the idea: Since there is no GUI, there’s no concept of mouse clicks. There’s no menu to choose options from, there’s no right click. Hence, you need a way to get all this on the keyboard — your only input source.

思维模型-理解这个想法:由于没有GUI,因此没有鼠标单击的概念。 没有菜单可供选择,没有右键单击。 因此,您需要一种将所有这些内容输入键盘的方法-您唯一的输入源。

Having two modes achieves this! You can think of the Normal ( Command) mode as the Menu bar and mouse on steroids, while the Insert mode is like the normal mode in GUI editors ( where what you type shows up on the screen ).

有两种模式可以实现这一目标! 您可以将“普通”(命令)模式视为类固醇上的菜单栏和鼠标,而“插入”模式则类似于GUI编辑器中的普通模式(您键入的内容将显示在屏幕上)。

话 (Words)

To Vim, words mean almost the same as what they mean to us — A set of characters separated by whitespace or special characters. The command is w.

对Vim而言,单词的含义几乎与我们的含义相同-一组由空格或特殊字符分隔的字符。 命令是w

命令解剖 (Command Anatomy)

Commands in Vim follow a set pattern. Knowing this would help put each command into a certain bucket of commands, thus building a better mental model for the same.

Vim中的命令遵循设定的模式。 知道这一点将有助于将每个命令放入特定的命令桶中,从而为相同的命令建立更好的思维模型。

Commands look like this:

命令如下所示:

[action] <number> [motion]

[动作] <数字> [动作]

The action is what you want to do,

动作就是你想做的,

The number is how many times you want to do that action,

该数字是您要执行该操作的次数,

The motion is the range of that action.

运动是该动作的范围。

The motion is the scope. An example would make this clearer. Let us say, we want to delete the next 3 words, starting from the cursor. Here, the action is delete, the number is 3 and the motion is a word. The command action for delete is d.

议案是范围。 一个例子可以使这一点更加清楚。 让我们说,我们要从光标开始删除接下来的3个单词。 此处,动作为删除,数字为3,动作为单词。 删除的命令操作是d

Hence, we get the final command as: d3w — delete the next 3 words.

因此,我们得到的最终命令为: d3w —删除接下来的3个单词。

Omitting the number defaults to once.

省略数字默认为一次。

Motions can be used without an action, which defaults to navigation. Hence, typing w in command mode would move the cursor forward one word.

无需动作即可使用动作,动作默认为导航。 因此,在命令模式下键入w将使光标向前移动一个单词。

We are well equipped now to start learning about the commands themselves (and a range of motions to use with them)

我们现在已经准备好开始学习命令本身(以及与它们一起使用的一系列动作)的知识。

有用的命令 (Useful commands)

如何关闭Vim (How to close Vim)

First things first, we don’t want to get stuck in Vim land without having an exit plan. Always have an exit strategy.

首先,我们不想在没有退出计划的情况下陷入Vim领域。 始终有退出策略。

:q to quit

:q退出

:q! to force quit

:q! 强迫戒烟

:wq to save and quit

:wq保存并退出

命令动作 (Command Actions)

d : delete

d :删除

i : insert

i :插入

p : put / paste

p :放置/粘贴

y : yank / copy

y :拉动/复制

x : cut

x :切

u : undo

u撤消

di: delete inside*, yi : yank inside*

di :删除内部*, yi :删除内部*

v : visual / selection

v :视觉/选择

/ : search

/ :搜索

% : parentheses matching, developers rejoice!

% :括号匹配,开发人员很高兴!

:s : substitute! In other words, find-replace on steroids

:s :替代! 换句话说,找到替代类固醇

Since actions on the entire line are very frequent, the developers of vim created a new shorthand for them — omitting the need to add a motion. Repeat the action to apply on the entire line. For example:

由于整个生产线上的动作非常频繁,因此vim的开发人员为他们创建了新的速记-无需添加动作。 重复该操作以应用于整行。 例如:

To delete the current line: dd

删除当前行: dd

To copy the current line: yy

复制当前行: yy

Neat, ain’t it?

整洁,不是吗?

指令动作 (Command motions)

Motions go with actions as we have seen, and the available motions changes with the action. However, some motions are pretty uniform.

如我们所见,动作与动作并存,可用动作随动作而变化。 但是,某些动作非常统一。

w : beginning of next word (we’ve seen this before!)

w :下一个单词的开头(我们之前已经看过!)

e : ending of current word

e :当前单词的结尾

b : beginning of previous word

b :上一个词的开头

Arrow keys / <h,j,k,l> : respective motions. h,j,k,l are a substitute to the arrow keys, and the source of speed in Vim: You don’t have to move your hands away from the typing part of the keyboard.

箭头键/ <h,j,k,l>:各自的动作。 h,j,k,l可以替代箭头键,也可以代替Vim中的速度来源:您不必将手从键盘的打字部分移开。

$ : end of line

$ :行尾

0 : beginning of line

0 :行首

G : end of file

G :文件结尾

nG : jump to line number n

nG :跳转到第n

) : jump forward a sentence

) :向前跳一个句子

} : jump forward a paragraph

} :向前跳一个段落

This helps visualise better:

这有助于更好地可视化:

ge      b          w                             e<-     <-         --->                          --->This is-a line, with special/separated/words (and some more). ~<----- <-----         -------------------->         ----->gE      B                   W                       E

Armed with these actions and motions, we can create most of the basic commands in Vim. Here’s a list of 8 every day functions. Figure out the command to make them happen!

有了这些动作和动作,我们就可以在Vim中创建大多数基本命令。 这是每天8个功能的列表。 找出使它们发生的命令!

  1. Delete the next 3 lines ( including current line)删除接下来的3行(包括当前行)
  2. Copy current word — cursor is at beginning of word复制当前单词-光标在单词的开头
  3. Copy current word — it has special characters — cursor is in the middle of the word复制当前单词-它具有特殊字符-光标位于单词中间
  4. Navigate down 10 lines向下浏览10行
  5. Delete everything inside the curly brackets删除大括号内的所有内容
  6. Go up 2 paragraphs上2段
  7. Paste the previously selected text 5 times.将先前选择的文本粘贴5次。
  8. Edit where the cursor is present: “I can Vim now!”编辑光标所在的位置:“我现在可以Vim!”

Wait for it…

等等...

Here are the solutions:

以下是解决方案:

  1. d3j

    d3j

  2. yw

    yw

  3. yiW : the yank inside is to yank inside, and W is inside what to yank ( current word). This is amazingly useful, you can use all sorts of combinations with inside !

    yiW :内部的yiW是内部的yiWW在内部的yiW是什么(当前单词)。 这非常有用,您可以将各种组合与inside

  4. 10j

    10j

  5. di} : just like #3.

    di} :就像#3。

  6. 2{ : this was slightly more intuitive. { is to go up a para, } is to go down a para

    2{ :这有点直观。 {是上一段, }是下一段

  7. 5p : remember the optional numbers from the command anatomy? They can be used almost anywhere

    5p :还记得命令解剖中的可选数字吗? 它们几乎可以在任何地方使用

  8. i I can Vim now! : i is to go into insert mode, then you can work like in a “normal” editor

    i I can Vim now!i将进入插入模式,然后您可以像在“常规”编辑器中一样工作

Alright, you made it! Congratulations, this is enough Vim to go about exploring on your own, adventurer. The tutorial is over. Good luck.

好吧,您做到了! 恭喜,这足以让Vim独自冒险。 本教程已结束。 祝好运。

If someone asks you about Vim, you can do better than using this meme. Explain it to them, or point them here ;)

如果有人问您有关Vim的问题,您可以比使用此模因做得更好。 向他们解释,或将其指向此处;)

*Note: This is my model of Vim. It isn’t exactly how things work internally. If you look at the documentation ( :help user-manual ), you’ll see that d is the command, and the motion is iw, or “inside word”. There’s a deviation.

*注意:这是我的Vim模型。 这并不是内部如何运作。 如果查看文档(:help user-manual),您会看到d是命令,并且运动是iw或“内部单词”。 有偏差。

奖金 (Bonus)

Here are some extra commands that come in handy:

以下是一些有用的额外命令:

分屏 (Split screen)

:vsplit <filename>

:vsplit <filena >

Creates a vertical splitting. Enables you to copy-paste from one screen to another.

创建垂直分割。 使您可以从一个屏幕复制粘贴到另一个屏幕。

To cycle between screen-splits: <ctrl-w> &lt;ctrl-w>

要在屏幕分割之间循环: <ctrl-w> &l t; ctrl-w>

Alternatively, you could use the arrow keys / hjkl like so:

另外,您可以像这样使用箭头键/ hjkl

<ctrl-w> h to go to previous screen.

<ctrl-w > h转到上一个屏幕。

You can close windows as you normally do (:q), or —

您可以像平常一样关闭窗口( :q ),或者-

:only — to close all other windows

:only —关闭所有其他窗口

多个标签 (Multiple Tabs)

:tabnew <filename> opens a new file in a new tab on Vim

:tabnew <filena me>在Vim的新标签页中打开一个新文件

:tabn to go to next tab ( or :gt )

:tabn转到下一个标签(或:gt )

:tabp to go to previous tab ( or :gT )

:tabp转到上一个标签(或:gT )

Again, you can copy-paste from one tab into another.

同样,您可以从一个选项卡复制粘贴到另一个选项卡。

You can map this combination to a key of your choice too!

您也可以将此组合映射到您选择的键!

I tried <Ctrl-Tab>, but that’s already reserved. What a bummer. Instead, we have:

我尝试了<Ctrl-T ab>,但是已经保留了。 真可惜 相反,我们有:

map <C-t><left> :tabp<cr>
map <C-t><right> :tabn<cr>

Which means <Ctrl-t> followed by the left or right arrow key would let you switch between tabs.

这意味着<CTRL-T>接着b y th ë勒ft or右箭头键将让你切换标签。

How exactly did I come up with this mapping? Check out this tutorial.

我是如何精确想到这个映射的? 查看本教程 。

Other stories in this series:

本系列中的其他故事:

  • How not to be afraid of Python anymore

    如何不再害怕Python

  • How not to be afraid of GIT anymore

    如何不再害怕GIT

Enjoyed this? Don’t miss a post again — subscribe to my mailing list!

喜欢这个吗? 不要再错过任何帖子-订阅我的邮件列表!

翻译自: https://www.freecodecamp.org/news/how-not-to-be-afraid-of-vim-anymore-ec0b7264b0ae/

vim block vim

vim block vim_如何不再害怕Vim相关推荐

  1. vim block vim_我如何学会爱Vim

    vim block vim by Sanchit Gera 通过Sanchit Gera 我如何学会爱Vim (How I learned to love Vim) I've had a bitter ...

  2. javascript_如何不再害怕JavaScript

    javascript 成为一名出色的Javascript开发人员要知道的事情 (Things to know to be a great Javascript developer) Have you ...

  3. git 代理 git_如何不再害怕GIT

    git 代理 git 了解减少不确定性的机制 (Understanding the machinery to whittle away the uncertainty) 到底什么是Git? (What ...

  4. 让学前端不再害怕英语单词(一)

    欢迎关注csdn前端领域博主: 前端小王hs email: 337674757@qq.com 前端交流群: 598778642 有很多跟着我学习的学生经常跟我抱怨前端的单词很多,学了css又忘了htm ...

  5. Mastering Vim Chapter 1: Getting Started 掌握Vim 第1章:入门

    Welcome to Mastering Vim, a book which will teach you to get good with Vim, its plugins, and its ide ...

  6. 【Linux系统】开发工具(上) {软件包管理器yum,更新yum源,文本编辑器vim,vim的四种基本模式,vim指令集,代码编译器gcc/g++}

    一.软件包管理器:yum 1.1 yum是什么? Linux下软件的安装方法: 源码安装:下载源码,在本地自行编译,然后才能安装. rpm安装:红帽软件包管理工具,属于安装包安装. yum安装:本身会 ...

  7. vim php psr2 插件,将vim打造成c++超级ide(vim插件安装)

    最近从MS Windows 转到了Liunx,花了一段时间熟悉和学习Liunx环境.有时候,真的很是怀念MS Vistual Studio那种超级智能的开发环境,总是想在Vim拾起那些曾进熟悉的符号, ...

  8. 让你不再害怕指针(一)

    2019独角兽企业重金招聘Python工程师标准>>> 你不再害怕指针 前言:复杂类型说明 要了解指针,多多少少会出现一些比较复杂的类型,所以我先介绍一下如何完全理解一个复杂类型,要 ...

  9. vi 查看最顶部_5分钟带你进入 Vim 大门,让你喜欢 Vim

    原标题:5分钟带你进入 Vim 大门,让你喜欢 Vim 来自:Linux迷 链接: https://www.linuxmi.com/vim-zhinan.html 打算在Linux上使用Vim文本编辑 ...

最新文章

  1. 基于 OpenCV 的人脸识别
  2. IIS FTP部分文件上传报错451的原因及解决方法
  3. cli/c++与C#比较之我见
  4. max与top的效率
  5. AJAX Tookits -- ConfirmButton
  6. PannerNode
  7. C语言学习笔记---文件操作 fopen()函数 和 fclose()函数
  8. D-Link 修复多个硬编码密码漏洞
  9. Spring单一类型依赖查找Bean
  10. talib函数功能一览表
  11. 泰国之旅随感(70天)
  12. 团队管理14--盘点团队
  13. 【干货】如何利用 pandas 批量合并 Excel?
  14. 蜡笔同步 java_蜡笔同步常见问题解析
  15. 搞点好玩儿的,如何做一个你自己的ad-block插件
  16. uC/OS_II操作系统移植,亲测可用
  17. html怎么引入框架,html文件中引入bootstrap框架
  18. VVC学习之五:帧内预测——67个模式预测信号生成 predIntraAng()
  19. [图解]PDF 格式概述(pdf structure)
  20. pymysql模块和SQL注入

热门文章

  1. Solr 中遇到的问题
  2. npm install 报错 npm ERR! code Z_BUF_ERROR 问题解决
  3. Angular CLI在线安装和离线安装
  4. scala语言运行递归“分鱼”程序
  5. 移动磁盘由于IO设备错误,要怎样寻回文件
  6. 单例测试模式中【饿汉式】与【懒汉式】的区别
  7. ceph存储引擎bluestore解析
  8. 自己动手——实现 Dustjs 中间件
  9. houdini + maya的pulldownit
  10. 简单ajax类, 比较小, 只用ajax功能时, 可以考虑它