当前位置:网站首页>GVIM/VIM使用技巧
GVIM/VIM使用技巧
2022-07-23 16:41:00 【qq_44985628】
博客概述
在Linux中最常使用的编辑器就是VIM,但是VIM的使用与Linux的使用基本一致,都是基于命令行操作,因为VIM也是只有命令没有菜单。那么,要想使用好VIM就必须记住一些常用的命令,方便我们使用VIM到达随心所欲的地步。这篇文章讲总结我们经常使用的VIM操作方式,供同学们学习以及方便博主日后复习。
VIM工作模式
VIM有三种工作模式,分别是命令模式,插入模式,编辑模式,其中插入模式与我们常用的txt文件的编写相差不大,但是命令模式以及编辑模式都是为了我们更快、更好的编写文件所提供的。
VIM常用的命令
命令模式下u表示撤销最近的操作。
VIM由命令模式变成插入模式的几种方式
| 命令 | 作用 |
|---|---|
| a | 在光标所在字符后插入 |
| A | 在光标所在行尾插入 |
| i | |
| I | 在光标所在行首插入 |
| o | 在光标下插入新行 |
| O | 在光标上插入新行 |
上面表格就是在VIM中由命令模式变成插入模式的几种方式。
定位命令
| 命令 | 作用 |
|---|---|
| :set nu | VIM编辑器显示行号 |
| :set nonu | VIM取消显示行号 |
| gg | 到第一行 |
| G | 到最后一行 |
| nG | 到第n行 |
| :n | 到第n行 |
| $ | 移至行尾 |
| 0 | 移至行首 |
删除命令
| 命令 | 作用 |
|---|---|
| x | 删除光标所在字符 |
| nx | 删除光标所在处后n个字符 |
| dd | 删除光标所在行 |
| ndd | 删除光标以及光标之后的n行 |
| dgg | 删除光标所在行之前所有的行 |
| dG | 删除光标所在行之后所有的行 |
| D | 删除光标所在行到行尾内容 |
| :n1,n2d | 删除指定范围的行 |
复制和剪切命令
| 命令 | 作用 |
|---|---|
| yy | 复制当前行 |
| nyy | 复制当前行以下n行 |
| dd | 剪切当前行 |
| ndd | 剪切当前行以下n行 |
| p,P | 粘贴在当前光标所在行下或行上 |
替换和取消命令
| 命令 | 作用 |
|---|---|
| r | 取代光标所在处字符 |
| R | 从光标所在处开始替换字符,按Esc结束 |
| u | 取消上一步操作 |
查找和替换命令
| 命令 | 作用 |
|---|---|
| /string | 搜索指定字符串 |
| set ic | 搜索时忽略大小写 |
| n | 搜索时指定字符串的下一个出现的位置 |
| :%s/old/new/g | 全文替换字符串,gc表示每一个字符串均需要自己手动判断最常用 |
| :n1,n2s/old/new/g | 在一定范围内替换字符串 |
保存命令
| 命令 | 作用 |
|---|---|
| :w | 保存修改 |
| :w new_filename | 另存为指定文件 |
| :wq | 保存修改并退出 |
| ZZ | 快捷键,保存修改并退出 |
| :q! | 不做修改退出 |
| :wq! | 保存修改并退出 |
VIM使用技巧
将另一个文件中的内容全部导入到当前文件
命令:在编辑模式下输入:r+导入文件的文件名
示例::r test.txt
在不退出VIM的前提下,执行Linux命令,并将执行后的结果打印到当前文件
命令:在编辑模式下输入:r !命令
示例::r !ls
在VIM编辑器中定义快捷键
命令:map 快捷键 触发命令
示例:map ^p I# <ESC>
单词的整体替换
命令: ab
示例:ab always always @(posedge sclk or negedge)
如何保存当前VIM设置的快捷键与整体替换
在当前用户下的文件夹下创建一个.vimrc的文件,将创建的快捷键写入该文件中
示例:vim root/.vimrc
边栏推荐
- What is the current situation of the next generation industry? 90% of career changing modelers are learning this process
- Modeling just learning is very confused. How to learn the next generation role modeling process?
- PCL:多直線擬合(RANSAC)
- Handwriting bind, call, apply is actually very simple
- Paddlenlp's UIE classification model [taking emotional propensity analysis news classification as an example] including intelligent annotation scheme)
- EmguCV 常用函数功能说明「建议收藏」
- sklearn 分类器常见问题
- 【2018】【论文笔记】石墨烯场效应管及【1】——GFETs的种类和原理,GFETs特性,GFETs在太赫兹中的应用和原理
- integer 和==比较
- LM393 low power dual voltage comparator parameters, pins, application details
猜你喜欢

【2018】【论文笔记】石墨烯场效应管及【2】——石墨烯的制备、转移
![JUC concurrent programming [detailed explanation and demonstration]](/img/08/a680e4686a34f7b177c2650f330dfb.png)
JUC concurrent programming [detailed explanation and demonstration]

MQ【MessageQueue 图文详解及四大MQ比较】

ros(27):rosparam简单使用与一种通过launch传递参数不成功与解决

基于FPGA的SPI通讯协议实现
![[2020] [paper notes] new terahertz detection - Introduction to terahertz characteristics, various terahertz detectors](/img/94/ff67867ef3237d8779628c8872b694.png)
[2020] [paper notes] new terahertz detection - Introduction to terahertz characteristics, various terahertz detectors

deepstream学习笔记(二):gstreamer与deepstream-test1说明

Gradle【图文安装及使用演示 精讲】

【2018】【论文笔记】石墨烯场效应管及【1】——GFETs的种类和原理,GFETs特性,GFETs在太赫兹中的应用和原理

Jetty 服务器的 NIO 机制是如何导致堆外内存溢出的
随机推荐
How to become a modeler? Which is more popular, industrial modeling or game modeling?
LeetCode 0131. 分割回文串
Redis【2022最新面试题】
电子元件-电阻
As a senior 3D modeler, I give some suggestions to novice learning partners to use
What is the use of tampermonkey?
OSI模型第一层:物理层,基石般的存在!
代码整洁,高效的系统方法
[2018] [paper notes] graphene FET and [2] - Preparation and transfer of graphene
An SQL question about grouping query
deepstream学习笔记(二):gstreamer与deepstream-test1说明
Opencv (13): brief introduction to cv2.findcontours, cv:: findcontours and description of cv2.findcontours function in various versions of opencv
Gradle [graphic installation and use demonstration]
Redis【超强超细 入门教程】
多线程与高并发day11
What does MySQL access port mean_ What is the port number of the database port
Navigation component of jetpack compose uses
PCL: ajustement multiligne (RANSAC)
Cell array processing
Building virtual private network based on softther