Vim User Manual 阅读笔记 usr_12.txt Clever tricks 花招

*12.1* Replace a word 替换一个词

REPLACING IN SEVERAL FILES 在多个文件中替换

vim *.cpp Start Vim, defining the argument list to contain all the C++ files. You are now in the first file.打开多个同类型文件

qq Start recording into the q register 录制到寄存器

:%s/\<GetResp\>/GetAnswer/g 执行替换

Do the replacements in the first file.

:wnext Write this file and move to the next one. 保存文件,切换到下一个文件。

q Stop recording. 结束录制

@q Execute the q register. This will replay the

substitution and ":wnext". You can verify

that this doesn't produce an error message. 执行寄存器

999@q Execute the q register on the remaining files. 多次执行寄存器内容

:%s/\<GetResp\>/GetAnswer/ge

The "e" flag tells ":substitute" that not finding a match is not an error. 参数e,告诉替换忽略找不到的错误。

*12.2* Change "Last, First" to "First Last"

替换正则式中,利用 \( \) 套住的内容 对应 \1 \2 进行交换位置, \0对应匹配整个匹配的pattern的内容。

*12.3* Sort a list

:.,/^$/-1!sort

把从 当前行 到 空行前一行(段末)进行排序

*12.4* Reverse line order 倒排所有行

:global/^/move 0

指定位置设置为 mark t ,然后移动到某个行------把mark t 和 当前行之间的所有行倒排序插入到t后面

:'t+1,.g/^/m 't

*12.5* Count words

当前光标停留单词位置 g CTRL-G

可视模式下,统计选中的区域单词数量等

*12.6* Find a man page *find-manpage*

unix下编辑shell或者C文件时,查找man page

停留在这个函数名上,大写 K

vim脚本编辑时,在vim帮助中查看也可以用

K 或者 \K

*12.7* Trim blanks

去掉所有尾部空格

:%s/\s\+$//

"\s\+". This finds white space characters (\\s), 1 or more of them (\\+), before the end-of-line ().

*12.8* Find where a word is used

UNIX 下查找包含单词 frame_counter 的某类文件,并使用vim打开

``vim `grep -l frame_counter *.c```

复制代码
##### *FINDING EACH LINE*

`:grep error_string *.c`

The ":grep" command uses the external commands grep (on Unix) or findstr

(on Windows). You can change this by setting the option 'grepprg'. 调用外部操作系统命令进行查找
相关推荐
菩提小狗2 小时前
小迪安全2023-2024|第5天:基础入门-反弹SHELL&不回显带外&正反向连接&防火墙出入站&文件下载_笔记|web安全|渗透测试|
笔记·安全·web安全
Wentao Sun2 小时前
致敬软件创业者2026
笔记·程序人生
深蓝海拓4 小时前
PySide6,QCoreApplication::aboutToQuit与QtQore.qAddPostRoutine:退出前后的清理工作
笔记·python·qt·学习·pyqt
酒鼎4 小时前
学习笔记(3)HTML5新特性(第2章)
笔记·学习·html5
嵌入小生0074 小时前
标准IO---核心函数接口延续(嵌入式Linux)
c语言·vscode·vim·嵌入式·小白·标准io·函数接口
LYOBOYI1234 小时前
vscode界面美化
ide·vscode·编辑器
山岚的运维笔记4 小时前
SQL Server笔记 -- 第20章:TRY/CATCH
java·数据库·笔记·sql·microsoft·sqlserver
Gain_chance4 小时前
33-学习笔记尚硅谷数仓搭建-DWS层交易域用户粒度订单表分析及设计代码
数据库·数据仓库·hive·笔记·学习·datagrip
承渊政道5 小时前
Linux系统学习【Linux系统的进度条实现、版本控制器git和调试器gdb介绍】
linux·开发语言·笔记·git·学习·gitee
lpfasd1235 小时前
两个美国:精英的知识崇拜与底层的反智驯化
笔记