当前位置: 首页 > 编程日记 > 正文

vim block vim_如何不再害怕Vim

vim block vim

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 Vim

    Vim大师

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

相关文章:

android EditText 限定中文个数与英文个数的解决方式

EditText 限定中文8个英文16个的解决方法。 在EditText上控件提供的属性中有限定最大最小长度的方法。可是&#xff0c;对于输入时&#xff0c;限定中文8个英文16个时&#xff0c;怎么办&#xff1f;相当于一个中文的长度是两个英文的长度。原理就不说了。自己看一下android的源…

根据二叉树的前序遍历和中序遍历重建二叉树

题目描述 输入某二叉树的前序遍历和中序遍历的结果&#xff0c;请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6}&#xff0c;则重建二叉树并返回。1 /**2 * Definition for …

VUE 监听当前路由 侦听器 watch

侦听器&#xff1a; 你可以利用侦听器&#xff0c;响应数据的变化&#xff0c;例如路由&#xff0c;和页面中data的值&#xff0c;可以在他们变化的时候写相应的处理逻辑在侦听器中。 侦听器的使用很简单&#xff1a; watch 对象就是侦听器&#xff0c;只有当侦听的值改变了它…

如何使用Bootstrap4和ES6创建自定义确认框

by Prashant Yadav通过Prashant Yadav 如何使用Bootstrap4和ES6创建自定义确认框 (How to create a custom confirm box with Bootstrap4 and ES6) We put lots of sweat into achieving a good design, but imagine a scenario where we have to use something which is styl…

RequireJS学习笔记(转)

前言进入移动前端是很不错的选择&#xff0c;这块也是我希望的道路&#xff0c;但是不熟悉啊。。。现在项目用的是requirebackbone&#xff0c;整个框架被封装了一次&#xff0c;今天看了代码搞不清楚&#xff0c;觉得应该先从源头抓起&#xff0c;所以再看看require了。上午是…

火狐中的table

在火狐浏览器中&#xff0c;table的th、td会存在小数转载于:https://www.cnblogs.com/likwin/p/7270817.html

React路由 react-router-dom

React的路由&#xff1a; 首先我们创建一个React应用 npm install -g create-react-app create-react-app demo-app cd demo-app安装路由 npm install react-router-dom npm add babel/runtime 接下来&#xff0c;将以下任一示例复制/粘贴到中src/App.js。 第一个示例&…

编程基础 垃圾回收_为什么我回收编程问题

编程基础 垃圾回收by Amy M Haddad通过艾米M哈达德(Amy M Haddad) 为什么我回收编程问题 (Why I Recycle Programming Problems) Many programmers are given the same advice: solve as many problems as possible. It’s true that solving new problems can help you gain …

SQL Server孤立账户解决办法

选择你想要的数据库。 执行 exec sp_change_users_login UPDATE_ONE,用户名,登录名 假如你的登录名是&#xff1a;sd exec sp_change_users_login UPDATE_ONE,sd,sd 转载于:https://www.cnblogs.com/runliuv/p/7273675.html

vue更新data无效,页面data没刷新 vue.set

Vue中组件的data是有很多坑的&#xff0c;先普及一下常识&#xff1a; 1.想使用data&#xff0c;必须先在data中创建。&#xff08;如果不创建就会报错&#xff09;示例&#xff1a; <div class"">{{user.Age}}</div>new Vue({el: #app,data: {user:{A…

重温Thinking in java

1、高精度 BigInteger、BigDecimal 支持任意大小的数字 不能使用运算符 运算速度相对于int、float稍慢 2、对象作用域 {String s new String("aaa"); } 在}外 此时栈中的引用s已经超出了自己的作用域 便不存在了 但是new String("aaa")这个堆中的对象仍然…

2018 react 大会_React Conf 2018的经验教训

2018 react 大会by Yangshun Tay阳顺泰 React Conf 2018的经验教训 (Lessons Learned at React Conf 2018) I was fortunate to have attended React Conf 2018 thanks to my managers — it was an awesome event. I have been watching past React Conf videos online and i…

删除url中某个参数

这里的url 是指一个网站链接 例如&#xff1a; https://baidu.com?a1&b2 下面看一下封装的代码 <!DOCTYPE html> <html><head><meta charset"utf-8"><script src"https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js&q…

【转载】MSXML应用总结 开发篇(下)

原文&#xff1a;http://blog.sina.com.cn/s/blog_48f93b530100eq4b.html 三、查询XML文档节点 这部分属于“读”XML文档并做节点遍历&#xff0c;由于担心加上实例会占用过多的篇幅影响阅读&#xff0c;先在这篇做方法总结&#xff0c;以后有时间再写一篇“实战篇”专门写个实…

d010:盈数、亏数和完全数

题目: 对一个正整数N而言&#xff0c;将它除了本身以外所有的因子加起来的总和为S&#xff0c;如果S>N&#xff0c;则N为盈数&#xff0c;如果S<N&#xff0c;则N为亏数&#xff0c;而如果SN&#xff0c;则N为完全数&#xff08;Perfect Number&#xff09;。例如10的因子…

软件开发 理想_我如何在12个月内找到理想的软件工作

软件开发 理想In this talk, Matt Woods shares the 3 cornerstone habits that helped him land his dream software job in just 12 months. These habits paved the way for him to consistently grow as a software developer, balloon his professional network, and easi…

Angular4.0从入门到实战打造在线竞拍网站学习笔记之四--数据绑定管道

Angular4.0基础知识之组件Angular4.0基础知识之路由Angular4.0依赖注入Angular4.0数据绑定&管道 数据绑定 数据绑定允许你将组件控制器的属性和方法与组件的模板连接起来&#xff0c;大大降低了开发时的编码量。 常见的表现形式有&#xff1a; 插值表达式&#xff1a;<h…

给GridView增加求和行

1、在WebForm窗体中&#xff0c;设置GridView的ShowFooter"True" 2、在后台代码中 private int jhrs0,ybrs0;//定义变量 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowIndex > 0) { jhrs Convert.ToInt16(e.Ro…

phpMyAdmin 数据库添加int类型的值时默认设为唯一主键的问题解决

数据库的表中插入了一条数据&#xff0c;再插入数据就插入不进去。 这是我今天在开发数据库的时候&#xff0c;遇到一个问题&#xff0c;经过排查&#xff0c;是数据库的结构有问题&#xff0c;有字段是唯一数据&#xff0c;但是目前还不想设置它的值。 场景环境描述&#xff…

python 类中定义类_Python中的动态类定义

python 类中定义类Here’s a neat Python trick you might just find useful one day. Let’s look at how you can dynamically define classes, and create instances of them as required.这是一个整洁的Python技巧&#xff0c;有一天可能会有用。 让我们看一下如何动态定义…

用自定义方法,传入成绩数组,实现输出考试成绩的成三名

package com.imooc; import java.util.Arrays; //导入Array类包 import java.util.Scanner; //导入Scanner类包 public class Final2 { public static void main(String args[]){Scanner…

EJS 什么是EJS后缀文件 EJS怎么用

一、什么是EJS EJS是一个JavaScript模板库&#xff0c;用来从JSON数据中生成HTML字符串。 二、为什么要使用EJS 与最初的JavaScript相比较&#xff0c;一些不太了解你的代码的人可以更容易地通过EJS模板代码看得懂你的代码。 让我们放松一下&#xff0c;一起来享受下令人激动的…

一个推荐系统,实现完整的设计-在百度搜索关键词推荐案例

在之前一篇博文中&#xff0c; 有同学在评论中问了个问题&#xff1a; 怎样解决因式分解带来的推荐冷门。热门关键词的问题。 在回答这个问题的时候&#xff0c; 想到了近几年在做搜索推荐系统的过程中&#xff0c; 学术界和工业界的一些差别。 正好近期正在做技术规划&#xf…

如何充分利用JavaScript(ES6)中的解构功能

by Joanna Gaudyn乔安娜高登(Joanna Gaudyn) Destructuring was a new addition to ES6. It took inspiration from languages like Python and allows you to extract data from arrays and objects into distinct variables. It might sound like something you’ve done in…

React 开发环境搭建

先来一个 React 官方文档的链接 点击跳转 搭建 React 的前期准备&#xff1a;你的本地环境需要安装 cnpm、node。 注&#xff1a;代码块中的 $ 代表&#xff1a; $后面是在命令行输入的命令&#xff0c;举例 $ npm start 解&#xff1a;实际上是应该打开命令行输入 npm st…

c++中的友元重载

1 语法 返回值类型 operator 运算符名称(形参列表) { 重载实体 } --------->operator和运算符名称在一起构造成新的函数名 2 案例 1 #include <iostream>2 3 using namespace std;4 5 class Complex6 {7 public:8 9 Complex(float x0,float y0) 10 :_…

WPF解析TTF 字体

偶遇需要自己解析 TTF 字体并显示&#xff0c;此做。。。 using System; using System.Collections.Generic; using System.Drawing.Text; using System.IO; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Windows; using System.W…

redux logic_Redux-Logic简介

redux logicby Sam Ollason通过萨姆奥拉森(Sam Ollason) Redux-Logic简介 (An Introduction to Redux-Logic) This article will go through a high-level overview of Redux-Logic. We will look at what is it, why it is needed, how it differs from other Redux middlewa…

[SDOI2009]HH的项链

题目背景 无 题目描述 HH 有一串由各种漂亮的贝壳组成的项链。HH 相信不同的贝壳会带来好运&#xff0c;所以每次散步完后&#xff0c;他都会随意取出一段贝壳&#xff0c;思考它们所表达的含义。HH 不断地收集新的贝壳&#xff0c;因此&#xff0c;他的项链变得越来越长。有一…

DvaJS 入门, 快速上手Dva

为什么要使用Dva? React 没有解决的问题 React 本身只是一个 DOM 的抽象层&#xff0c;使用组件构建虚拟 DOM。 如果开发大应用&#xff0c;还需要解决一个问题。 通信&#xff1a;组件之间如何通信&#xff1f;数据流&#xff1a;数据如何和视图串联起来&#xff1f;路由…