惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
S
Schneier on Security
Scott Helme
Scott Helme
C
Check Point Blog
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
N
News and Events Feed by Topic
B
Blog
P
Privacy International News Feed
I
Intezer
T
Threatpost
Google DeepMind News
Google DeepMind News
L
LangChain Blog
Last Week in AI
Last Week in AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LINUX DO - 最新话题
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cybersecurity and Infrastructure Security Agency CISA
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News | PayPal Newsroom
The Hacker News
The Hacker News
S
Security @ Cisco Blogs
罗磊的独立博客
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
大猫的无限游戏
大猫的无限游戏
U
Unit 42
Hacker News: Ask HN
Hacker News: Ask HN
D
Docker
AI
AI
小众软件
小众软件
博客园 - 叶小钗
H
Help Net Security
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog

博客园 - 陌上花kai

openclaw实践 RooCode结合NacosMCP实践 Dify0.15.1升级1.4.3版本 RooCode结合本地MCP实践 本地密码管理器-Vaultwarden 从业务视角看AI落地:避免技术狂欢,聚焦真实需求 从"我要去山西旅游"看AI智能体的未来之旅:大模型如何重构自动化服务生态 OpenManus+DeepSeek体验 企业知识库落地实践 搭建个人AI知识库-DIFY 搭建个人AI知识库:RAG与本地模型实践指南 分享一个前后端分离后台管理系统 CV高手是怎么炼成的? linux下自建NAS教程 一个9年archlinux重度使用者自述 在日常工作和生活中使用Linux-开篇 springboot集成测试最小化依赖实践 ChatGpt怎么玩 如何通过电脑手柄玩安卓手游?
vim系列-文本操作篇
陌上花kai · 2024-08-30 · via 博客园 - 陌上花kai

基数行与偶数行分组

使用Vim的替换命令,可以轻松地将基数行和偶数行分组:

%s/\(^.*$\)\n\(^.*$\)/\1 \2/g

然后,删除所有的基数行:

%s/^.*$\n\(^.*$\)/\1/g

删除重复行

在Vim中删除重复行是一个常见的操作,以下是几种方法:

删除相邻重复行

:g/\(.\+\)$\n\1/d

删除不相邻重复行

使用排序命令删除不相邻的重复行:

:sort u

删除重复行,结果按照原顺序排列

为了保存原有顺序,首先给每行加上行号和1个{

:let i=1|g/^/s//\=i.'{'/|let i+=1

按照行号后面的内容排序:

:sort /^\d\{-}/

删除行号后面的内容相同的行保留后面的行:

:g/^\d\{-}\{.∗$\n\d\{-}\{1$/d

按照行号恢复顺序:

:sort n

删除空白行

删除文件中的空白行:

%g/^\s*$/d

添加序号

有多种方法可以为文本添加序号:

通过let变量

let i=1 | g/^/s//\=i.' '/ | let i=i+1

直接使用行号

:g/^/ s//\=line('.').' '

使用range()函数

:for i in range(1, 31)
:  call setline(i, i .' '. getline(i))
:endfor

利用Vim的编程支持

:python <<EOF
from vim import current
for i in range(len(current.buffer)):
current.buffer[i] = str(i+1) + ' ' + current.buffer[i]
EOF

外部命令

使用外部命令如findstr, sed, diff, perl, python等为文本添加序号:

:%!findstr /N "^"
:%!sed =|sed "N;s/\n/ /"
:%!diff --line-format=%dn%L % -
:%!perl -pe "print ++$a . ' '"
:%!python -c "import sys,fileinput as f;[sys.stdout.write(str(f.lineno())+a) for a in f.input()]"

查看文件行数、列数、字符数及所占字节大小

查看文件的行数、列数、字符数及所占字节大小:

g + <Ctrl-g>