[Shell Tools] - Editor (Vim)

6 篇文章 0 订阅
4 篇文章 0 订阅
本文详细介绍了Vim编辑器的四种基本操作模式:正常、插入、替换和视觉模式,以及如何在这些模式间切换。在正常模式下,使用ESC键返回;插入模式用于输入文本;替换模式用于替换现有文本;视觉模式则允许选择文本块。此外,还讲解了基本的命令行操作、文本移动、选择和编辑技巧,如查找、替换、删除、复制、粘贴等。通过掌握这些,可以大幅提升Vim的使用效率。
摘要由CSDN通过智能技术生成

1. Operating Modes

  • Normal: for moving around a file and making edits, press <ESC> to switch from any mode back to Normal mode.
  • Insert: for inserting text, press i in normal mode to enter Insert mode.
  • Replace: for replacing text, press r in normal mode to enter Replace mode.
  • Visual: for selecting blocks of text, press v/V in normal mode to enter Visual / Visual Line mode, press <C-v> to enter Visual Block mode.
  • Command-line: for running a command, press : in normal mode to enter Command-line mode.

2. Basic

Command-line

  • :q quit
  • :q! quit anyway (without making any change)
  • :w write (save)
  • :wq write and quit
  • :e {name of file} open file for editing
  • :ls show open buffers
  • :help {topic} show open buffers

Movement

  • Basic movement: hjkl (left, down, up right)
  • Word: w/W (next word), b/B (beginning of last word), e/E (end of word)
  • Lines: 0 (beginning of line), ^ (first non-blank character), $ (end of line), { / } (beginning / end of a paragraph)
  • Screen: H (head of screen), M (middle of screen), L (bottom of screen)
  • Scroll: <C-u/f> (page-up / forward), <C-d/b> (page-down / backward), <C-e> (scroll up), <C-y> (scroll down)
  • File: gg (beginning of file), G (end of file)
  • Line numbers: :{number}<CR> or {number}G (go to line {number})
  • Misc: % (corresponding item)
  • Find: f{character} (find), F{character} (find backward), t{character} (till), T{character} (back till), use ,/; to repeat operations.
  • Search: /{regex} / ?{regex}, n/N for navigating matches

Selection

Use Visual modes

Edit

  • o / O insert line below / above
  • d{motion} e.g. dw - delete word, d$ - delete to end of line, d0 - delete to beginning of line
  • c{motion} e.g. cw - change word
  • x delete character
  • s substitute character ( = xi)
  • u undo, <C-r> redo
  • y copy / yank, Y copy line
  • p paste

Counts

verb + num + noun

Modifiers

  • i inside
  • a around

3. Advanced

Search and Replace

  • %s substitute command
:%s/x/y/g	" change all x to y

Multiple Windows

  • :sp / :vsp split windows
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值