Thumbnail: Linux

CS6.NULL Lecture3

by on under Linux
3 minute read

Editor modules

  • Normal: ESC
  • Insert: i
  • Replace: R
  • Visualize: v V CR-V
  • Command line: :

Command line

  • :q 退出(关闭窗口)
  • :w 保存
  • :wq 保存并退出
  • :e {文件名} 打开要编辑的文件
  • :ls 显示打开的缓存
  • :help {标题} 打开帮助文档
    • :help :w 打开 :w 命令的帮助文档
    • :help w 打开 w 移动的帮助文档

Normal mode

  • 基本移动: h j k l (左下上右)
  • Word: w (按词跳跃 word), b (跳到词首 begin), e (跳到词尾 end)
  • Line: 0 (行首), ^ (第一个非空字符), $ (行尾)
  • Screen: H (屏幕首行 head), M (屏幕中间 middle), L (屏幕底部 last)
  • Page: Ctrl-u (向上翻 up), Ctrl-d (向下翻 down)
  • File: gg (文件头), G (文件尾)
  • line num: :{行数}CR (在命令行输入行号 + CR(回车)) 或者 {行数}G / {行数}gg (在 NORMAL 模式下输入行号 + gg / G)
  • 匹配括号: % (跳到匹配的 () / [] / {} / ‘’ / “” / /**/ 的另一半)
  • Find: f{字符}, t{字符}, F{字符}, T{字符}
    • f / F 向后查找字符,t / T 向前查找字符
    • , / ; 用于导航匹配
  • Search: /{正则表达式}
    • n: 下一个 (next)
    • N: 上一个

Visual mode

  • visual: v
  • visual line: V
  • visual block: Ctrl + v
  • double click to quit visual
  • use move command to choose

Insert mode

  • i 进入插入模式
  • O / o 在光标 上一行 / 下一行 插入行并进入编辑模式
  • d{移动命令} 删除{移动语句} (delete)
    • dw 删除词,d$ 删除到行尾,d0 删除到行首,dd 删除整行
  • c{移动命令} 改变{移动语句} (change)
    • cw 改变词
    • 等价于 d{移动命令} + i
  • x 删除字符, 等价于 dl
  • s 替换字符, 等价于 xi
  • 可视化模式下可进行操作
    • 选中文字 + d 可以删除(剪切)
    • 选中文字 + c 可以更改
  • u 撤销 (undo)
  • C-r 重做 (redo)
  • y 复制 (yank) d 剪切
  • p 粘贴 (paste)
  • ~ 改变选中部分字符大小写
  • . 重复之前的操作
    • 比如在打完 “hello” 后按 . 就会重复输入 “hello”。
    • 比如在执行过 x 后,按 . 则重复 x 指令。

Tricks

  • 3w 向后移动 3 个词
  • 5j 向下移动 5 行
  • 7dw 删除 7 个词
  • ci( 改变当前括号内的内容
  • ci[ balabala
  • da' 删除引号及引号内容
  • da( 删除括号及括号内容

vimrc

My vimrc

call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'preservim/nerdtree'
call plug#end()

" Use <Tab>to navigate the completion list
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"

" Use <C-n> to open NERDTreeToggle
map <C-n> :NERDTreeToggle<CR>

set nu

set shortmess=atI

syntax on

set nobackup

set confirm

set tabstop=4
set autoindent
set cindent
set shiftwidth=4
set softtabstop=4

set hlsearch

set background=dark

set noswapfile

set showmatch

imap kj <ESC>
inoremap ' ''<ESC>i
inoremap ( ()<ESC>i
inoremap [ []<ESC>i
inoremap { {<CR>}<ESC>O
Linux