vim 编辑演示

Hi, fellow coders! You may have heard of the Vim code editor before, or even used it a bit.

嗨,各位编码员! 您可能以前听说过Vim代码编辑器,甚至使用过它。

There are plenty of resources out there that cover the basics of Vim and I don't want to just do another rewrite of those here. Instead, I want to share some quick tips that I've learned from others while using Vim full time at work.

有很多资源涵盖了Vim的基础知识,我不想在这里再次重写这些内容。 相反,我想分享一些我在全职使用Vim时从他人那里学到的快速技巧。

These are tiny things that you can learn quickly that will make a big difference in your day-to-day work in Vim. They'd definitely made my life easier.

这些都是很小的事情,您可以快速学习,这将对您在Vim中的日常工作产生很大的影响。 他们肯定使我的生活更轻松。

Remember: Vim comes pre-installed on Mac and Linux. You just need to open up your terminal and type "vim" in the command prompt, and you'll open Vim. If you have a Windows computer, follow these instructions to install Vim on your PC.

切记:Vim预先安装在Mac和Linux上。 您只需要打开终端并在命令提示符下键入“ vim”,即可打开Vim。 如果您有Windows计算机,请按照以下说明在PC上安装Vim 。

开始之前 (Before we begin)

If you're interested in Vim but haven't started yet, these are the resources I'd like to recommend:

如果您对Vim感兴趣但还没有开始,这些是我想推荐的资源:

  • OpenVim - Interactive Vim Tutorial

    OpenVim-交互式Vim教程

  • vimtutor - this is an interactive command line tutorial that's available and installed on Macs and some Linux distros. Just type vimtutor in your terminal

    vimtutor-这是一个交互式命令行教程,可在Mac和某些Linux发行版上安装。 只需在终端中输入vimtutor

  • VimAdventures - First couple of levels are free, and if you like the format, and the full license is $25

    VimAdventures-前几个级别是免费的,如果您喜欢这种格式,则完整许可证为25美元

If you like Vim but it's too much to run it on its own, install a Vim extension for your favourite editor, like VS Code or Sublime or any other. That way you get to use the quick actions and shortcuts of Vim and a friendlier interface you're more used to.

如果您喜欢Vim,但要单独运行它实在太多了,请为您喜欢的编辑器安装Vim扩展,例如VS Code或Sublime或任何其他。 这样,您就可以使用Vim的快速操作和快捷方式以及更习惯的友好界面。

One important realization I had about learning and working with Vim: you don't need to master everything (which is practically impossible anyway) to start using it.

我对学习和使用Vim的一个重要认识是:您不需要掌握一切(实际上几乎是不可能的)就可以开始使用它。

Once you figure out the basics, every time you have a question or a block throughout your workday, write it down, and then go through that list and search the Internet for how to do that in Vim.

一旦掌握了基础知识,在工作日中每次遇到问题或遇到障碍时,请写下来,然后遍历该列表并在Internet上搜索如何在Vim中做到这一点。

This way, you will incrementally fill any gaps you might have and will become better with each new little thing you add to your repertoire (these micro-improvements will be similar to the tips in this article below).

这样,您将逐步填补可能存在的空白,并且会随着添加到曲目库中的每一个新的小东西而变得更好(这些微改进将类似于下面的本文技巧)。

Now let's proceed to the fun stuff – the tips and tricks. You don't have to have any Vim plugins installed to take advantage of these.

现在,让我们继续学习有趣的东西-技巧和窍门。 您无需安装任何Vim插件即可利用它们。

1.如何以正确的缩进量开始在一行上书写 (1. How to start writing on a line at correct indentation)

Before I learned this, I used to jump on a new line and go to insert mode, TAB to the right indentation and start typing code. With this little trick, you won't have to do do all the extra tabbing, it will just place you in insert mode at the right indentation.

在我学到这一点之前,我曾经跳到新行并进入插入模式,即TAB到正确的缩进位置并开始键入代码。 有了这个小技巧,您不必做所有额外的制表符,它只会使您处于插入模式的正确缩进位置。

RECIPE: S (SHIFT+s)

配方: S (SHIFT + s)

DEMO:

演示:

2.自动调整窗口大小 (2. Resize windows automatically)

Very often we do something with windows inside Vim that causes them to be resized incorrectly, sometimes one being way too wide and the other way too narrow.

通常,我们在Vim中使用窗口来做某些事情,导致窗口的大小不正确,有时一个窗口太宽而另一个窗口太窄。

The easiest way to see that effect is to open 3 windows in one Vim tab and resize the terminal window in which you opened Vim.

看到这种效果的最简单方法是在一个Vim选项卡中打开3个窗口,并调整打开Vim的终端窗口的大小。

You want to resize the windows to all be the same size, with available space evenly distributed. Good news is, you don't have to do it manually.

您希望将窗口的大小全部调整为相同大小,并均匀分配可用空间。 好消息是,您不必手动进行操作。

RECIPE: CTRL+w =

配方: CTRL+w =

The combination of CTRL+w, followed by pressing the equals sign key will equalize the windows.

CTRL + w的组合键,然后按等号键,将使窗口相等。

DEMO:

演示:

3.跳至匹配的括号/括号 (3. Jump to the matching bracket/brace)

With your cursor on a square [ or round ( bracket or a curly brace {, press % (SHIFT+5) to jump to its matching symbol. Press it again to jump back (toggle between them).

将光标放在方形[或圆形(括号或花括号{上,按%(SHIFT + 5))跳到其匹配的符号。再次按它跳回来(在它们之间切换)。

if (condition) {// code
}
// If your cursor was on {, and you pressed %, you'd jump to }

RECIPE: % with your cursor on the character you want to find a match to.

配方: % ,将光标放在要与之匹配的字符上。

DEMO:

演示:

4.缩进/取消缩进一行或多行 (4. Indent/Unindent a line or multiple lines)

>> ⁠– indents a line
<< ⁠– unindents a line

When you have multiple lines selected (in VISUAL LINE mode), you only need to press > or < once to indent or unindent the lines (as shown in demo below)

当您选择了多行时(在VISUAL LINE模式下),您只需按一次>或<就可以缩进或取消缩进(如下面的演示所示)

It doesn't matter where your cursor is positioned in the line when indenting - it will still work. After indent is done, cursor is auto-positioned on first non-empty character in the line.

缩进时光标在行中的位置无关紧要-仍然可以使用。 缩进完成后,光标将自动定位到该行中的第一个非空字符上。

RECIPE: One line: >>, <<. Multiple lines: >, <.

配方:一行: >><< 。 多行: ><

DEMO:

演示:

5.修复整个文件中的缩进 (5. Fix indentation in the whole file)

Start in the top of a file (to get there, press gg anywhere in the file.). Then press =G, and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.

从文件顶部开始(要到达该位置,请在文件中的任何位置按gg 。)。 然后按=G ,Vim将在整个文件中修复缩进。 如果您不从文件的开头开始,它将固定从当前行到文件底部的缩进。

RECIPE: =G

配方: =G

Press the equals sign, followed by SHIFT+G

按等号,然后按SHIFT + G

DEMO:

演示:

6.使用标签的基础 (6. Basics of working with tabs)

Often you want to be looking at multiple files or contexts at the same time. Vim tabs are very handy but underutilized feature for this. I don't know of any other editor that supports this (but I'm sure there is a way to do it elsewhere).

通常,您希望同时查看多个文件或上下文。 Vim选项卡非常方便,但是使用不足。 我不知道有任何其他编辑器支持此功能(但是我敢肯定有其他方法可以做到这一点)。

For example, I like to keep my code related files in my main tab, and in another tab: README with a TODO list and a place I can jot down further ideas.

例如,我想将与代码相关的文件保留在主选项卡中,并保留在另一个选项卡中:README(带有TODO列表的自述文件)和一个可以记下更多想法的位置。

To write the commands to work with tabs, you will need to be in command mode. To start writing the command, press : and type. The command will show up in the left bottom corner of the editor as you are typing. Press enter to execute.

要编写使用选项卡的命令,您将需要处于命令模式。 要开始编写命令,请按:并输入。 键入时,该命令将显示在编辑器的左下角。 按Enter执行。

RECIPE: :tabnew creates a new tabgt - go to next tabgT - go to previous tab:tabo - close all other tabs besides the active one

方药: :tabnew创建一个新的标签gt -进入下一选项卡gT -到前一个标签:tabo -关闭所有其他选项卡除了有源一个

DEMO:

演示:

7.如何快速返回上一个文件 (7. How to quickly go back to a previous file)

Often, when you edit a file with code, you open another one in the same window. Then it's not so easy to come back to the one you just worked on. You could list buffers and navigate to the previous one but you need to remember its name for that and spend your precious time. Vim users don't like to spend too much time on actions. :) So you can use CTRL+o for this.

通常,使用代码编辑文件时,会在同一窗口中打开另一个文件。 然后回到刚才的工作并不是那么容易。 您可以列出缓冲区并导航到上一个缓冲区,但是您需要记住该缓冲区的名称并花费宝贵的时间。 Vim用户不喜欢在动作上花费太多时间。 :)因此,您可以为此使用CTRL + o。

All it does is that it finds a previous position of your cursor - and if it happened to be in a different file (the one you just lost by opening a new one), it jumps us right back there.

它所做的只是找到光标的上一个位置-如果它碰巧在另一个文件中(您刚刚通过打开一个新文件而丢失了),它将使我们跳回到那里。

Thank you for reading and I hope these tips serve you well!

vim 编辑演示_改变我生活的7个Vim技巧(含演示)相关推荐

  1. pythonvim编辑教程_使用vim编辑python

    1.vim使用 1.vim进入 vim  1.py         有文件打开无文件新建 2.命令模式 :进入末行模式 3.末行模式 :wq      保存并退出         :q      退出 ...

  2. xshell vim 不能粘贴_编辑器之神——vim的入门指南

    编辑器之神--Vim的操作说明 ©作者:geekctwd Vim命令模式: Vim虽然被称为编辑器之神,但是很多接触过的人都说入门较难,原因是什么呢,除了vim繁杂的按键之外就是因为它的模式了,很多初 ...

  3. csdn模拟人生_模拟人生改变我生活的5个原因

    csdn模拟人生 The first time that I discovered The Sims was 12 years ago. I distinctly remember seeing it ...

  4. vim切换编程语言_把 Vim 打造成源代码编辑器 - C 语言编程透视

    前言 程序开发过程中,源代码的编辑主要是为了实现算法,结果则是一些可阅读的.便于检错的.可移植的文本文件.如何产生一份良好的源代码,这不仅需要一些良好的编辑工具,还需要开发人员养成良好的编程修养. L ...

  5. linux 普通用户退出vim,Linux环境下VI/VIM编辑文件时无权限保存的解决方法(普通用户)...

    在Linux环境下,如果直接使用VI/VIM命令编辑没有修改权限的文件时,保存的时候就会提示用户无法进行保存操作,一般的解决方法只能是关闭文件重新以sudo权限打开该文件编辑后再保存(前提是用户具有s ...

  6. vim 删除行_【收藏】138条 Vim 命令、操作、快捷键全

    关注我,你的眼睛会怀孕 命令历史以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令.启动vim在命令行窗口中输入以下命令即可vim 直接启动vimvim filenam ...

  7. dos命令窗口光标闪烁_史上最全的Vim命令(二)

    8. 排版 8.1 基本排版 << 向左缩进一个shiftwidth >> 向右缩进一个shiftwidth :ce(nter) 本行文字居中 :le(ft) 本行文字靠左 : ...

  8. vim编辑修改二进制文件以及对于二进制文件中幻数测试

    vim编辑修改二进制文件以及对于二进制文件中幻数测试 这篇博客将讲述我在学习反汇编时遇到的关于编辑二进制文件的问题. 编辑环境:Ubuntu + vim 我测试的文件是一个可执行文件,也就是通过c程序 ...

  9. 烛光晚餐矢量图(编号:82204)_日常生活_矢量人物_矢量素材

    烛光晚餐矢量图(编号:82204)_日常生活_矢量人物_矢量素材 烛光晚餐矢量图(编号:82204)_日常生活_矢量人物_矢量素材 posted on 2013-12-03 10:58 lexus 阅 ...

最新文章

  1. Linux下的redis的持久化,主从同步及哨兵
  2. 【机器学习基础】时间序列测试题的40题,看看你对时间序列的了解水平
  3. mysql正确打开方式_MySQL中MVCC的正确打开方式
  4. TimingWheel 时间轮详解
  5. 两个不同分支之间的代码合并
  6. php注册树模式,php设计模式-注册树模式
  7. 报错,Error in created hook: “SyntaxError: Unexpected token o in JSON at position 1“
  8. 卡尔曼滤波的基本原理
  9. GTK实现简单计算器(calculator.c)
  10. Leetcode | Pow(x, n)
  11. 【IT】jQuery AJAX Call to MVC Controller with Parameters
  12. 记录 || 雨后王母山仙境
  13. 从北京站到天通苑怎么走,
  14. 计算机科普小知识大全,电脑小白知识科普 10个Win10实用技巧科普
  15. C语言实现英寸单位与厘米的转换(两种方法)特简单!!!
  16. ISA SERVER常见问题总结专用贴(转)
  17. 忆阻蔡氏电路matlab,基于有源带通滤波器的忆阻蔡氏电路研究.doc
  18. Python爬虫---影评的爬取
  19. 【PTA乙级练习题】topic:1001
  20. 解决路由环路问题的方法

热门文章

  1. 文本的数据导入到数据库中 mysql
  2. 代码控制树视图 c# 1614262980
  3. 更新显示当前歌曲的名称 winform 0130
  4. DataView对象的用法 1207
  5. django模板变量的使用详解 200309
  6. 算法--库函数实现全排列
  7. 自定义注解--Annotation
  8. Spring Cloud Zuul中使用Swagger汇总API接口文档 1
  9. Hadoop集群(第10期副刊)_常用MySQL数据库命令
  10. 学习了时间和测试题目