当前位置: 首页 > article >正文

[Vim][常用操作整理]详细讲解

请添加图片描述


目录

  • 0.说明
  • 1.Cursor Movement
  • 2.Insert Mode
  • 3.Editing
  • 4.Marking Text (Visual Mode)
  • 5.Visual commands (In Visual mode)
  • 6.Registers
  • 7.Mark and Positions
  • 8.Macros
  • 9.Cut and paste
  • 10.Indent text
  • 11.Exiting
  • 12.Search and replace
  • 13.Diff


0.说明

  • 为何是全英文?
    • 本篇文章为本人的一次尝试,之所以用全英文介绍,也是为了和读者一起熟悉全英文文档
      • 虽说是全英文的文档,但是还是很浅显易懂的
    • 如果有读者需要一份中文版本,可以评论或者私聊,我会考虑再出一份中文版本的
  • 内容方面
    • 本文整理出的操作,都是基础语法之外的一些操作及一些常用组合
    • 同时,部分操作我只给出了一个例子,其他操作是同理的,相信学过Vim基础的小伙伴是可以自己发散开的
    • 没有Vim基础的小伙伴,也不用担心,我后面会出Vim的基础教程~

1.Cursor Movement

  • HHome,move to top of screen
  • MMiddle,move to middle of screen
  • LLow,move to bottom of screen
  • 0:jump to the start of the line
  • }:jump to next paragraph (or function/block, when editing code)
  • {:jump to previous paragraph (or function/block, when editing code)

2.Insert Mode

  • ea:insert (append) at the end of the word
  • Ctrl + hdelete the character before the cursor during insert mode
  • Ctrl + wdelete the word before the cursor during insert mode
  • Ctrl + jbegin new line during insert mode
  • Ctrl + t:indent(move right) line one shiftwidth during insert mode
  • Ctrl + d:de-indent(move left) line one shiftwidth during insert mode
  • Ctrl + n:insert(auto-complete) next match before the cursor during insert mode
  • Ctrl + p:insert(auto-complete) previous match before the cursor during insert mode
  • Ctrl + rx:insert the contents of register x
  • Ctrl + ox:Temporarily enter normal mode to issue one normal-mode command x.

3.Editing

  • rReplace,replace a single character.
  • RReplace Mode,replace more than one character, until ESC is pressed.
  • JJoin,join line below to the current one with one space in between.
  • gJ:join line below to the current one without space in between.
  • gwip:reflow paragraph.
  • xpTranspose,transpose two letters(delete and paste).
  • u:undo.
  • UUndo Line,restore (undo) last change line.

4.Marking Text (Visual Mode)

  • v:start visual mode, mark lines, then do a command (like y-yank)
  • V:start linewise visual mode.
  • o:move to other end of marked area.
  • Ctrl + v:start visual block mode.
  • O:move to other corner of block.
  • aw:mark a word.
  • ab:a block with ().
  • aB:a block with {}.
  • at:a block with <> tags.
  • ib:inner block with ().
  • iB:inner block with {}.
  • it:inner block with <> tags.
  • Tip:Instead of b or B one can also use ( or {, respectively.

5.Visual commands (In Visual mode)

  • >:shift text right
  • <:shift text left
  • y:yank (copy) marked text
  • d:delete marked text
  • ~:switch case
  • u:change marked text to lowercase
  • U:change marked text to uppercase
  • Tip:Mark first, then operate

6.Registers

  • Registers are being stored in ~/.viminfo, and will be loaded again on next restart of vim.
  • Special registers
    • 0:last yank
    • ":unnamed register, last delete or yank
    • %: current file name
    • #: alternate file name
    • *:clipboard contents (X11 primary)
    • +:clipboard contents (X11 clipboard)
    • /:last search pattern
    • ::last command-line
    • .:last inserted text
    • -:last small (less than a line) delete
    • =:expression register
    • _:black hole register

7.Mark and Positions

  • :marks:list of marks
    • ma:set current position for mark A
    • `a:jump to position of mark A
    • y`a:yank text to position of mark A
    • `0:go to the position where Vim was previously exited
    • `":go to the position when last editing this file
    • `.:go to the position of last editing this file
    • ` `:go to the position before the last last jump
  • :ju[mps]:list of jumps
    • Ctrl + i:go to newer position in jump list
      • Jump forward
    • Ctrl + o:go to older position in jump list
      • Jump backwards
  • :changes:list of changes
    • g:go to newer position in change list
    • g;:go to older position in change list
  • Ctrl + ]:jump to the tag under cursor
    • This is a common command for viewing code definitions in Vim.
    • When the cursor is over an identifier, such as a function name or variable name, use Ctrl + ]to jump to the definition of that identifier
  • Tip:To jump to a mark you can either use a backtick (`) or an apostrophe ('). Using an apostrophe jumps to the beginning (first non-blank) of the line holding the mark.

8.Macros

  • qa:record macro a
  • q:stop recording macro
  • @a:run macro a
  • @@:rerun last run macro

9.Cut and paste

  • p:put (paste) the clipboard after cursor
  • P:put (paste) before cursor
  • gp:put (paste) the clipboard after cursor and leave cursor after the new text
  • gP:put (paste) the clipboard before cursor and leave cursor after the new text
  • d$ or D:delete (cut) to the end of the line

10.Indent text

  • >>:indent (move right) line one shiftwidth
  • <<:de-indent (move left) line one shiftwidth
  • >%:indent a block with () or {} (cursor on brace) line one shiftwidth
  • >ib:indent inner block with ()
  • >at:indent a block with <> tags
  • 3==:re-indent 3 lines
  • =%:re-indent a block with () or {} (cursor on brace)
  • =iB:re-indent inner block with {}
  • gg=G:re-indent entire buffer
  • ]p:paste and adjust indent to current line

11.Exiting

  • :wqa:write (save) and quit on all tab

12.Search and replace

  • @pattern:‘very magic’ pattern: non-alphanumeric characters are interpreted as special regex symbols (no escaping needed)
  • :noh[lsearch]:remove highlighting of search matches

13.Diff

  • za:toggle fold under the cursor
  • zo:open fold under the cursor
  • zc:close fold under the cursor
  • zr:reduce (open) all folds by one level
  • zm:fold more (close) all folds by one level
  • zi:toggle folding functionality
  • ]c:jump to start of next change
  • [c:jump to start of previous change
  • Tip:The commands for folding (e.g. za) operate on one level. To operate on all levels, use uppercase letters (e.g. zA)

http://www.kler.cn/a/451382.html

相关文章:

  • Scala_【1】概述
  • 单机游戏《野狗子》游戏运行时提示dbghelp.dll缺失是什么原因?dbghelp.dll缺失要怎么解决?
  • OpenAI 普及 ChatGPT,开通热线电话,近屿智能深耕AI培训
  • 金仓数据库安装-Kingbase v9-centos
  • 本科阶段最后一次竞赛Vlog——2024年智能车大赛智慧医疗组准备全过程——13使用Resnet-Bin
  • 解释下什么是面向对象?面向对象和面向过程的区别?
  • 音视频学习(二十七):SRT协议
  • Excel 列名称转换问题 Swift 解答
  • LeetCode 343.整数拆分
  • #渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍11基于XML的SQL注入(XML-Based SQL Injection)
  • 考前96天 学习巩固 计算机、数学、英语
  • leetcode 3132. 找出与数组相加的整数 II 中等
  • MySQL追梦旅途之慢查询分析工具mysqldumpslow和pt-query-digest
  • Maximum Crossings (Hard Version)最大交叉次数(困难版本)
  • ROS1入门教程5:简单行为处理
  • 【es6复习笔记】生成器(11)
  • C++-------回溯最大最小算法
  • Word表格批量添加题注代码
  • 反汇编一个简单的C程序
  • MySQL的架构设计和设计模式
  • 面试记录24年新
  • 乐乐音乐Flutter版
  • OceanBase之primary_one概念学习
  • call、bind、apply的区别
  • Python OCR 文字识别
  • 基于若依的ruoyi-nbcio-plus支持VForm3表单字段数据保存到数据库的一种方法——全网首创(二)