vi笔记2——vi之简单编辑

2023-11-02

vi笔记2——vi之简单编辑

vi 简单编辑主要包含以下内容:
• Moving the cursor
• Adding and changing text
• Deleting, moving, and copying text
• More ways to enter insert mode


相关命令说明如下:

c,d,y can use like this
(number)(cmd)(text object)
(cmd)(number)(text object)

a --append text after cursor
A or $a --append text at the end of the line

c 命令行下使用c,就会从光标处清除相应的字符
cc --to replace the entire current line,equal to S(large)
C(large c) --equal to c$ ,replace words from current cursor to the end of the line
cw --To the end of a word
c2b --Back two words
c$ --To the end of line
c0 --To the beginning of line

d --delete
ndd --delete n lines from current line
d2w 2dw --delete two words
db --delete backward
D or d$ -- deletes from the cursor position to the end of the line
d0 -- delete to the beginning of a line
de --To retain the space between words, use de, which deletes only to the end of a word.
dE --deletes to the end of a word, including punctuation.

ngg --go to line n,equal to nG
1gg --go to line 1,equal to command mode(:1)
$g or G --go to the last line of the file,equal to command mode(:$)

nh --move n space to the left

i --insert before the corsor
typing 25a*- or 25i*- ESC appends or inserts 50 characters (25 pairs of asterisk and hyphen).
 I  --insert at the head of a line

nj --down n lines
J --join,Joining Two Lines with J,nJ will join n lines

nk --up n lines

nl --right n space

o(small o) --Open blank line  below cursor for text.
create a new line after current line,and be inserting mode 
O(large O) --Open blank line above cursor for text.
create a new line before current line,and be inserting mode

p --put, d x yy后的缓存数据可以直接用来粘贴
If you delete one or more lines, p puts the deleted text on a new line(s) below the cursor. If you delete less than an entire line, p puts the deleted text into the current line, after the cursor.

r or R-- (replace)选中某个字符,并且设置为可改变状态,如:rs将选中的字符变为s,rw将选中的字符变为w,2rs将两个字符变为s
R (“large” replace) is useful when you want to start changing text, but you don’t know exactly how much.
小r只能替换一个字符,大R可以从当前光标处不停的替换

s(small s) --Substituting text,substitute a single character,and be inserting mode
ns will substitute n characters
S(large s) --lets you change whole lines,equal to cc,put you in inssert mode
nS --change n lines,equal to ncc

u --undo,undo your last undo with u,如果误删了数据,如dd某一行,可以使用u来撤销上一次的命令,p命令也可以粘贴删除的内容(x dd等内容在缓存中,用可以p来粘贴),(VI)page 296 has more undoing functions.
U, the uppercase version of u, undoes all edits on a single line, as long as the cursor remains on that line. Once you move off a line, you can no longer use U.
Vim lets you use CTRL-R to “redo” an undone operation.

w word,以一个块为单位的移动

x --deletes only the character the cursor is on
nx --delete n characters from the cursor
nX --delete n characters before the cursor
说明:点(.),当使用x后点和小x一样删除光标右边的,当使用大X后点和大X一样删除光标左边的
 
y --yank
nyy or nY --copy n lines
yw --copy one word
y$ --copy to the end of a line
y0 --copy to the begin of a line

~ --The tilde (~) command will change a lowercase letter to uppercase or an uppercase letter to lowercase.

.(dot) --Repeating or Undoing Your Last Command

summary:
Table 2-1. Edit commands
Text object			        Change 			Delete 			Copy
One word        	                cw 			dw 			yw
Two words,not counting punctuation      2cW or c2W              2dW or d2W              2yW or y2W
Three words back                        3cb or c3b 		3db or d3b 		3yb or y3b
One line 			        cc 			dd 			y or Y
To end of line 	                        c$ or C 		d$ or D 		y$
To beginning of line                    c0 		        d0 			y0
Single character 	                r 			x or X 			yl or yh
Five characters 	                5s 			5x 			5yl

Table 2-2. Movement
Movement Commands
← , ↓ , ↑ , → h, j, k, l
To first character of next line 	 	                +
To first character of previous line                             -
To end of word 							e or E
Forward by word  						w or W
Backward by word 						b or B
To end of line  						$
To beginning of line  					        0

Table 2-3. Other operations
Operations Commands
Place text from buffer 					P or p
Start vi, open file if specified  		        vi file
Save edits, quit file 					ZZ or :wq
No saving of edits, quit file  			        :q!

Table 2-4. Text creation and manipulation commands
Editing action Command
Insert text at current position  		i
Insert text at beginning of line   		I
Append text at current position  		a
Append text at beginning of line  		A
Open new line below cursor for new text         o(小写字母 欧)
Open new line above cursor for new text         O(大写字母 欧)
Delete line and substitute text  		S
Overstrike existing characters with new text    R
Join current and next line  			J
Toggle case  					~
Repeat last action  				.
Undo last change  				u
Restore line to original state  		U


以上是学习vim时候整理的一些要点,分享此处以供学习!

对于一些想深入学习vi的人群,可以参考以下图书:Learning.the.vi.and.Vim.Editors.7th

下载链接: http://download.csdn.net/detail/u011127242/9617946

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

vi笔记2——vi之简单编辑 的相关文章

  • 终端 vim 中的语法高亮显示,但 gVIM 中没有

    我目前在终端中使用 VIM 并且有完美的语法突出显示 但是当我尝试使用 gvim 时 无论什么类型的文件或输入多少次 syntax on 我都没有得到任何语法突出显示 有人有什么想法吗 谢谢 这是我的 vimrc 供感兴趣的人使用 Turn
  • 如何从 Vim 中发送转义序列?

    因此 最近苹果公司支持在终端的状态栏中显示工作目录和文件 必须发送的转义序列 以设置当前文件 是这样的 ESC 6 Pt BEL where Pt is a file url 指向当前正在编辑的文件 所以我想我可以让 Vim 发送这个命令作
  • 如何使用 vim 作为“git log”编辑器?

    当我跑步时git log 编辑器到底是什么git log正在使用 Also 无论如何我可以使用吗vim作为我的默认编辑器git log 如果我想搜索 git 日志 最好的方法是什么 现在我正在做类似的事情 git log grep bla
  • 如何在 Vim 中创建行号和文本之间的边框

    我希望在行号右侧和文本左侧有一条细边框线 您可以使用不同的颜色来突出显示LineNr 例如 hi LineNr cterm bold ctermbg gray ctermfg black gui bold guibg gray guifg
  • MacVim:跨窗口共享命名寄存器?

    我想跨 MacVim 窗口共享命名寄存器缓冲区 就像我在单个实例中跨缓冲区一样 换句话说 假设我标记了一个位置 m 然后去其他地方 我将一些文本拉入寄存器 a 从当前点到 m a m 然后我转到另一个窗口 不 我不是指同一窗口中的另一个分割
  • 如何在 vim 中覆盖 ~/.vim 和 ~/.vimrc 路径(但不能覆盖其他路径)?

    假设我有一个所有 vim 配置的 tarball 通常在 vim 中的所有内容 插件 自动加载 颜色 所有这些东西 和一个 vimrc 文件 我将其提取到某个目录中 所以在我所在的目录 PWD 中 有一个 vim 文件夹和一个 vimrc
  • 如何设置打开文件时默认展开?

    In my vimrc我已经把set foldmethod syntax启用方法折叠等 但是 我不喜欢每次打开文件时都会折叠整个文件的默认设置 有没有办法启用foldmethod 但是当我打开文件时文件是否展开了 set foldlevel
  • Vim 扩展(通过 Python)?

    是否可以通过自定义扩展 最好用 Python 编写 来扩展 vim 功能 理想情况下 我需要的是在命令模式下的自定义命令 例如 ESC do this do that vim 支持 python 脚本 我认为也支持 perl 您只需确保您使
  • 设置 Vim 背景颜色

    当我尝试更改背景颜色时 vimrc或者直接在 Vim 中使用以下命令 set background dark 这根本不影响我的背景 也没有light选项 不过 当我运行 gvim 时 看起来还不错 有没有办法在不更改 Konsole 设置的
  • 如何在Vim中正确显示UTF-8字符

    我想要 需要编辑包含 UTF 8 字符的文件 并且我想使用 Vim 在我被指责问以前问过的问题之前 我已经阅读了有关编码 文件编码 s 术语编码等的 Vim 文档 用 google 搜索了该主题 并阅读这个问题 https stackove
  • Vim 状态栏预测/完成?

    昨天我玩了一些 vim 脚本 并设法对我目前正在输入的内容进行一些超出状态栏的预测 通过循环 请参阅屏幕截图 灰色 黄色条 问题是 我不记得我是如何得到它或找到我用于 vim 魔法的代码片段 我记得它非常简单 它要么是文档中的示例 要么是我
  • 使用关键字启动 syn 区域

    我想用 virtual 启动一个区域 以用不同的颜色突出显示所有虚拟方法 但是 virtual 已经在 cpp vim 文件中定义为关键字 因此永远不会执行区域匹配 我尝试了以下方法 syn region cVirtualMethod st
  • 在 Mac OS X 中将 Caps Lock 用作 Esc

    How do I make Caps Lock work like Esc in Mac OS X Edit As described in this answer https stackoverflow com a 40254864 66
  • git commit 保存 vim 文件时出错

    我正在遵循简单的 git 指南nettuts 简易 git 指南 http net tutsplus com tutorials other easy version control with git 我在我的中初始化了一个空的 git 实
  • Vim、Javascript、DoctorJS (jsctags) 和 Taglist(源代码浏览)

    我已经安装了DoctorJS http doctorjs org 之前jsctags 试图为 Vim 获得一些好的源代码浏览 标签列表 使用Taglist http www vim org scripts script php script
  • 通过列表字符仅显示前导空格的“空格”字符

    Vim 中是否可以有我的编辑器 编辑时 c and h文件 显示通过listchars 一个特殊字符 仅用于leading空格字符 我发现一个单独的帖子指出 从版本 7 4 开始 Vim 现在支持通过以下方式突出显示所有空格字符listch
  • vim 中的语法高亮

    当我在 vim 中打开语法颜色时 我无法在黑色上阅读深蓝色 如何更改一些默认颜色或模式颜色 例如 http www vim org scripts script php script id 1571 http www vim org scr
  • 如何在 Vim 中突出显示 Bash 脚本?

    我的 Vim 编辑器自动突出显示 PHP 文件 vim file php HTML 文件 vim file html 等等 但是当我输入 vim file在里面写一个Bash脚本 它不会突出显示它 我如何告诉 Vim 将其突出显示为 Bas
  • Vim 插入模式下光标线颜色变化

    有一个很好的片段可以改变光标颜色 if term xterm rxvt use an orange cursor in insert mode let t SI
  • vim 按语法高亮类型搜索

    我正在将 i18n 添加到现有项目 Web 应用程序 这涉及到用对 i18n 库的调用来替换静态文本的每一位 如果能够搜索该文本 而不是依靠语法突出显示来直观地识别它 将会很方便 在 vim 中 是否可以在文件中搜索特定突出显示类型的出现

随机推荐

  • 深度学习模型参数量计算

    若你的模型parameters为7327930 则 7327930 4 Byte 1024 1024 27 95 MB
  • 【Git详解大全】

    文章目录 1 Git 概述 1 1 版本控制 2 Git常用命令 2 1 初始化本地库 2 3 添加到暂存区 2 4 提交本地库 2 5 修改文件 2 7 历史版本 3 分支操作 3 1 什么是分支 3 2 分支的操作 4 Git团队协作
  • theos linux环境,MAC OS X下的Linux环境

    关键字 HomeBrew 好比Windows下的Cygwin 安装Homebrew 该si胜过macport ruby e curl fsSL https raw githubusercontent com Homebrew install
  • 【知识分享】C语言应用-易错篇

    一 C语言简介 C语言结构简洁 具有高效性和可移植性 因此被广泛应用 但究其历史的标准定义 C语言为了兼容性在使用便利性作出很大牺牲 在 C陷阱与缺陷 一书中 整理出大部分应用过程中容易出错的点 本文为 C陷阱与缺陷 的浓缩版本 想要更详细
  • 009 5道例题讲解函数递归——“C”

    函数递归是什么 程序调用自身的编程技巧称为递归 recursion 递归做为一种算法在程序设计语言中广泛应用 一个过程或函数在其定义或说明中有直接或间接 调用自身的一种方法 它通常把一个大型复杂的问题层层转化为一个与原问题相似的规模较小的问
  • Leetcode2486-追加字符以获得子序列

    双指针遍历即可 class Solution public int appendCharacters string s string t int n s size m t size int l 0 r 0 while l
  • 连接游戏服务器网络延迟高,网络延迟_连wifi玩游戏网络延迟高-太平洋IT百科

    网络延迟是游戏玩家最不能忍的 为了解决网络延迟的问题 玩家们装了光纤 换了路由 然而 为你我用了半年的积蓄 玩个农药还跳ping 开局两分钟 延迟400ms 网络延迟在王者荣耀中卡得连鲁班七号都表示 我想静静 连WIFI玩游戏网络延迟高怎么
  • 为什么动态库不能被其他动态或静态库包含

    如果静态库包含了动态库 则动态库失去了它的意思 因为动态库是在运行时调用的 如果包含在静态库里 意味着在编译时把动态库编译进去了 gcc不会做这么荒唐的事的 如果动态库包含了动态库 这也没必要 因为运行时可以直接调用了 为什么还要包含到另一
  • 腾讯云服务器搭建小皮面板phpstudy教程

    腾讯云控制台设置 找到自己服务器所在的实例 这里可以获得远程登录的账号密码 域名解析在下面添加自己ip解析到购买的域名就好了 搭建云服务器及php环境搭建教程如下 方包用的是windows server 服务器 适合新手 不像linux那样
  • GDI+ 中路径渐变画刷的使用

    背景 路径是一系列相互连接的直线和曲线 由许多不同类型的点所构成 用于表示复杂的不规则图形 GraphicsPath 类表示 路径渐变画刷允许设置颜色从中心向边界渐变的画刷 可以设置中心点颜色和边界点的颜色 构建路径渐变画刷 使用路径构建
  • Linux命令集锦-持续更新

    centos版本 CentOS Linux release 7 6 1810 Core 一 查看端口占用 lsof Linux安装 sudo yum install lsof Mac安装 brew install lsof lsof i p
  • 2020年排名前10的前端框架

    Ant Design 网站链接 https ant design index cn 蚂蚁金服出品 非常著名的框架 就算你不了解前端 也会在公司的项目中多少听到程序员说起过 目前很多公司都在用 已经很成熟 而且提供了对设计师友好的 Sketc
  • tensorflow目标检测api使用过程中的问题

    tensorflow目标检测api使用过程中的问题 使用环境 win10 pycharm开发平台 所有的依赖包都是用pip安装的 按照官方要求把api的依赖库装完之后在测试的时候提示no module named object detect
  • xshell卸载不干净导致无法安装

    卸载xshell 删除两个地方的注册表 Windows 文件夹下 C Program Files x86 InstallShield Installation Information 这个目录下 删了这个文件夹 F3FDFD5A A201
  • 【译】Hard Forks, Soft Forks, Defaults and Coercion

    区块链领域的一个重要论据是硬叉或软叉是否是首选的协议升级机制 两者之间的基本区别在于 软叉通过严格减少有效的交易集来改变协议的规则 所以遵循旧规则的节点仍然会进入新链 假设大多数矿工 验证者实施叉 而硬叉允许以前无效的交易和块变得有效 所以
  • centos7部署tomcat

    1 下载tomcat和jdk的tar gz包 并放在 root目录下 链接 https pan baidu com s 1fsJh8f6 rQxFzA5SIzUSfw 提取码 6zmg 2 解压文件 tar xf apache tomcat
  • [PCIe]LTSSM与电源管理

    1 LTSSM LTSSM全称是Link Training and Status State Machine 有以下11个状态 Detect Polling Configuration Recovery L0 L0s L1 L2 Hot R
  • 【cfeng work】什么是云原生 Cloud Native

    WorkProj 内容管理 云原生 云原生应用 十二要素应用 cfeng的work理解 本文introduce 云原生 Cloud Native相关内容 随着技术的迭代 从最初的物理机 gt 虚拟机 从单机 gt 分布式微服务 现在的热门概
  • C语言自定义函数求和

    include
  • vi笔记2——vi之简单编辑

    vi笔记2 vi之简单编辑 vi 简单编辑主要包含以下内容 Moving the cursor Adding and changing text Deleting moving and copying text More ways to e