2

vim常用命令与技巧(不定期更新).md

 1 year ago
source link: https://cloudsjhan.github.io/2019/04/21/vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E4%B8%8E%E6%8A%80%E5%B7%A7-md/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

vim常用命令与技巧(不定期更新).md

发表于 2019-04-21

| 分类于 vim

| 阅读次数:

| 字数统计: 323

|

阅读时长 ≈ 1

vim常用的命令与技巧总结

Vim常用的命令与技巧总结:

  1. 在每行行首添加相同的内容:
:%s/^/要添加的内容
  1. 在每行行尾添加相同的内容:
:%s/$/要添加的内容
  1. 利用正则表达式删除代码段每行的行号
:%s/^\s*[0-9]*\s*//gc

其中,^表示行首,$表示行尾,\s表示空格,[0-9]表示0~9的数字,*表示0或多个,%s/^\s*[0-9]*\s*//gc的意思是将每行以0或多个空格开始中间包含0或多个数字并以0或多个空格结束的字符串替换为空。
  1. 指定行首添加”#”
:447,945 s/^/#
447-945行的行首添加 #
  1. 删除每行前面的内容
:10,15 s/^/#//gc
  1. 统计m到n行中”字符串”出现的次数
:m,n s/字符串//gn
  1. 统计”字符串”在当前编辑文件出现的次数

    : %s/字符串/ng
  2. 统计词语在文件中出现的行数:

cat file|grep -i 字符串 |wc -l
  1. pycharm中vim插件批量缩进:
:m,n >
//向右缩进4空格

:m,n <
//向左缩进4空格
  1. 跳转到行首: ^
  2. 跳转到行尾:$
  3. 跳转到文件开头: gg
  4. 跳转到行尾:G

-------------The End-------------
坚持原创技术分享,您的支持将鼓励我继续创作!
(>给这篇博客打个分吧<)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK