Vim 模式 All In One

发布时间 2023-04-13 13:10:12作者: xgqfrms

Vim 模式 All In One

Vim 模式

normal mode 正常模式

visual mode 可视化模式

command mode 命令模式

insert mode 插入模式 i/ eidt mode 编辑模式

select mode 选择模式

ex mode 扩展模式

Vim modes

https://vimdoc.sourceforge.net/htmldoc/intro.html#vim-modes-intro

5. Modes, introduction				*vim-modes-intro* *vim-modes*

Vim has six BASIC modes:


					*Normal* *Normal-mode* *command-mode*
Normal mode		In Normal mode you can enter all the normal editor
			commands.  If you start the editor you are in this
			mode (unless you have set the 'insertmode' option,
			see below).  This is also known as command mode.

Visual mode		This is like Normal mode, but the movement commands
			extend a highlighted area.  When a non-movement
			command is used, it is executed for the highlighted
			area.  See |Visual-mode|.
			If the 'showmode' option is on "-- VISUAL --" is shown
			at the bottom of the window.

Select mode		This looks most like the MS-Windows selection mode.
			Typing a printable character deletes the selection
			and starts Insert mode.  See |Select-mode|.
			If the 'showmode' option is on "-- SELECT --" is shown
			at the bottom of the window.

Insert mode		In Insert mode the text you type is inserted into the
			buffer.  See |Insert-mode|.
			If the 'showmode' option is on "-- INSERT --" is shown
			at the bottom of the window.

Command-line mode	In Command-line mode (also called Cmdline mode) you
Cmdline mode		can enter one line of text at the bottom of the
			window.  This is for the Ex commands, ":", the pattern
			search commands, "?" and "/", and the filter command,
			"!".  |Cmdline-mode|

Ex mode			Like Command-line mode, but after entering a command
			you remain in Ex mode.  Very limited editing of the
			command line.  |Ex-mode|

There are six ADDITIONAL modes.  These are variants of the BASIC modes:


				*Operator-pending* *Operator-pending-mode*
Operator-pending mode	This is like Normal mode, but after an operator
			command has started, and Vim is waiting for a {motion}
			to specify the text that the operator will work on.

Replace mode		Replace mode is a special case of Insert mode.  You
			can do the same things as in Insert mode, but for
			each character you enter, one character of the existing
			text is deleted.  See |Replace-mode|.
			If the 'showmode' option is on "-- REPLACE --" is
			shown at the bottom of the window.

Virtual Replace mode	Virtual Replace mode is similar to Replace mode, but
			instead of file characters you are replacing screen
			real estate.  See |Virtual-Replace-mode|.
			If the 'showmode' option is on "-- VREPLACE --" is
			shown at the bottom of the window.

Insert Normal mode	Entered when CTRL-O given in Insert mode.  This is
			like Normal mode, but after executing one command Vim
			returns to Insert mode.
			If the 'showmode' option is on "-- (insert) --" is
			shown at the bottom of the window.

Insert Visual mode	Entered when starting a Visual selection from Insert
			mode, e.g., by using CTRL-O and then "v", "V" or
			CTRL-V.  When the Visual selection ends, Vim returns
			to Insert mode.
			If the 'showmode' option is on "-- (insert) VISUAL --"
			is shown at the bottom of the window.

Insert Select mode	Entered when starting Select mode from Insert mode.
			E.g., by dragging the mouse or <S-Right>.
			When the Select mode ends, Vim returns to Insert mode.
			If the 'showmode' option is on "-- (insert) SELECT --"
			is shown at the bottom of the window.


Vim 模式转换

mode-switching

https://vimdoc.sourceforge.net/htmldoc/intro.html#mode-switching

image

Vim 6 种基本模式

Normal mode

https://vimdoc.sourceforge.net/htmldoc/intro.html#Normal

Visual mode

https://vimdoc.sourceforge.net/htmldoc/visual.html#Visual

Select mode

https://vimdoc.sourceforge.net/htmldoc/visual.html#Select

Insert mode

https://vimdoc.sourceforge.net/htmldoc/insert.html#Insert

Command-line mode / Cmdline mode

https://vimdoc.sourceforge.net/htmldoc/cmdline.html#Command-line
https://vimdoc.sourceforge.net/htmldoc/cmdline.html#Cmdline

Ex mode

https://vimdoc.sourceforge.net/htmldoc/intro.html#Ex

Vim 6 种附加模式

There are six ADDITIONAL modes. These are variants of the BASIC modes:
有六种附加模式。 这些是 BASIC 模式的变体:

Operator-pending mode

https://vimdoc.sourceforge.net/htmldoc/intro.html#Operator-pending

Replace mode
https://vimdoc.sourceforge.net/htmldoc/insert.html#Replace

Virtual Replace mode

https://vimdoc.sourceforge.net/htmldoc/visual.html#Visual
https://vimdoc.sourceforge.net/htmldoc/insert.html#Replace

Insert Normal mode

https://vimdoc.sourceforge.net/htmldoc/insert.html#Insert
https://vimdoc.sourceforge.net/htmldoc/intro.html#Normal

Insert Visual mode

https://vimdoc.sourceforge.net/htmldoc/insert.html#Insert
https://vimdoc.sourceforge.net/htmldoc/visual.html#Visual

Insert Select mode

https://vimdoc.sourceforge.net/htmldoc/insert.html#Insert
https://vimdoc.sourceforge.net/htmldoc/visual.html#Select

(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

Vim 使用文档

https://vimdoc.sourceforge.net/htmldoc/usr_toc.html

$ vim --help
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 01 2021 01:51:08)

用法: vim [参数] [文件 ..]       编辑指定的文件
  或: vim [参数] -               从标准输入(stdin)读取文本
  或: vim [参数] -t tag          编辑 tag 定义处的文件
  或: vim [参数] -q [errorfile]  编辑第一个出错处的文件

参数:
   --			在这以后只有文件名
   -v			Vi 模式 (同 "vi")
   -e			Ex 模式 (同 "ex")
   -E			Improved Ex mode
   -s			安静(批处理)模式 (只能与 "ex" 一起使用)
   -d			Diff 模式 (同 "vimdiff")
   -y			容易模式 (同 "evim",无模式)
   -R			只读模式 (同 "view")
   -Z			限制模式 (同 "rvim")
   -m			不可修改(写入文件)
   -M			文本不可修改
   -b			二进制模式
   -l			Lisp 模式
   -C			兼容传统的 Vi: 'compatible'
   -N			不完全兼容传统的 Vi: 'nocompatible'
   -V[N][fname]		Be verbose [level N] [log messages to fname]
   -D			调试模式
   -n			不使用交换文件,只使用内存
   -r			列出交换文件并退出
   -r (跟文件名)		恢复崩溃的会话
   -L			同 -r
   -A			以 Arabic 模式启动
   -H			以 Hebrew 模式启动
   -T <terminal>	设定终端类型为 <terminal>
   --not-a-term		Skip warning for input/output not being a terminal
   --ttyfail		Exit if input or output is not a terminal
   -u <vimrc>		使用 <vimrc> 替代任何 .vimrc
   --noplugin		不加载 plugin 脚本
   -p[N]		打开 N 个标签页 (默认值: 每个文件一个)
   -o[N]		打开 N 个窗口 (默认值: 每个文件一个)
   -O[N]		同 -o 但垂直分割
   +			启动后跳到文件末尾
   +<lnum>		启动后跳到第 <lnum> 行
   --cmd <command>	加载任何 vimrc 文件前执行 <command>
   -c <command>		加载第一个文件后执行 <command>
   -S <session>		加载第一个文件后执行文件 <session>
   -s <scriptin>	从文件 <scriptin> 读入正常模式的命令
   -w <scriptout>	将所有输入的命令追加到文件 <scriptout>
   -W <scriptout>	将所有输入的命令写入到文件 <scriptout>
   -x			编辑加密的文件
   --startuptime <file>	Write startup timing messages to <file>
   -i <viminfo>		使用 <viminfo> 取代 .viminfo
   --clean		'nocompatible', Vim defaults, no plugins, no viminfo
   -h  或  --help	打印帮助(本信息)并退出
   --version		打印版本信息并退出

Vim 8.x / Vi IMproved 8.2

$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 01 2021 01:51:08)
包含补丁: 1-2434
Extra patches: 8.2.3402, 8.2.3403, 8.2.3409, 8.2.3428
修改者 team+vim@tracker.debian.org
编译者 team+vim@tracker.debian.org
巨型版本 无图形界面。  可使用(+)与不可使用(-)的功能:
+acl               -farsi             +mouse_sgr         +tag_binary
+arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        +termguicolors
-balloon_eval      -footer            +multi_lang        +terminal
+balloon_eval_term +fork()            -mzscheme          +terminfo
-browse            +gettext           +netbeans_intg     +termresponse
++builtin_terms    -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              -perl              +title
-clientserver      +job               +persistent_undo   -toolbar
-clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     +keymap            +postscript        +vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      +langmap           +profile           +virtualedit
+comments          +libcall           -python            +visual
+conceal           +linebreak         -python3           +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          +rightleft         +wildignore
+cursorshape       -lua               -ruby              +wildmenu
+dialog_con        +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       -X11
-dnd               +mouse             -sound             -xfontset
-ebcdic            -mouseshape        +spell             -xim
+emacs_tags        +mouse_dec         +startuptime       -xpm
+eval              +mouse_gpm         +statusline        -xsmp
+ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+extra_search      +mouse_netterm     +syntax            -xterm_save
     系统 vimrc 文件: "$VIM/vimrc"
     用户 vimrc 文件: "$HOME/.vimrc"
 第二用户 vimrc 文件: "~/.vim/vimrc"
      用户 exrc 文件: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
         $VIM 预设值: "/usr/share/vim"
编译方式: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Wdate-time -g -O2 -ffile-prefix-map=/build/vim-I0JMpS/vim-8.2.2434=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 
链接方式: gcc -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lm -ltinfo -lselinux -lacl -lattr -lgpm -ldl 

Vim 实战 REPL

$ shiyanlou:~/ $ vim --version[12:27:56]
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 07 2019 15:35:43)
Included patches: 1-1689
Extra patches: 8.0.0056
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
# ...

从 vi 衍⽣出来的 Vim 具有多种模式,这种独特的设计容易使初学者产⽣混淆
几乎所有的编辑器都会有插入和执行命令两种模式,并且大多数的编辑器使用了与 Vim 截然不同的方式:
命令目录(鼠标或者键盘驱动),组合键(通常通过 control 键(CTRL)和 alt 键(ALT)组成)或者鼠标输入。
Vim 和 vi ⼀样,仅仅通过键盘来在这些模式之中切换
这就使得 Vim 可以不⽤进⾏菜单或者⿏标操作,并且最小化组合键的操作。
对文字录入员或者程序员可以大大增强速度和效率。

Vim 具有 6 种基本模式5 种派生模式6 种派⽣模式;

  1. 普通模式(Normal mode)

在普通模式中,用的编辑器命令,比如移动光标,删除文本等等。
这也是 Vim 启动后的默认模式
这正好和许多新用户期待的操作方式相反(大多数编辑器默认模式为插入模式)。

Vim 强大的编辑功能来自于其普通模式命令, 普通模式命令往往需要一个操作符结尾。
例如普通模式命令dd删除当前行,但是第一个"d"的后面可以跟另外的移动命令来代替第二个d,比如dj用移动到下一行的"j"键就可以删除当前行和下一行。
另外还可以指定命令重复次数,2dd(重复dd两次),和dj的效果是一样的。
用户学习了各种各样的文本间移动跳转的命令和其他的普通模式的编辑命令,并且能够灵活组合使用的话,能够比那些没有模式的编辑器更加高效地进行文本编辑

在普通模式中,有很多方法可以进入插入模式, 比较普通的方式是按 a(append/追加)键或者 i(insert/插入)键。

  1. 插入模式(Insert mode)

在这个模式中,大多数按键都会向文本缓冲中插入文本。
大多数新用户希望文本编辑器编辑过程中一直保持这个模式。

在插入模式中,可以按 ESC 键回到普通模式。

  1. 可视模式(Visual mode)

这个模式与普通模式比较相似
但是移动命令扩大高亮的文本区域。高亮区域可以是字符或者是一块(任意多行)文本。
当执行一个移动命令时,命令会被执行到这块高亮的区域上。
Vim 的"文本对象"也能和移动命令一样用在这个模式中。

如何,使用鼠标选中一块文本,按一次d 键就可以删除这一块文本。❓

  1. 选择模式(Select mode)

这个模式和无模式编辑器的行为比较相似(Windows 标准文本控件的方式)。
这个模式中,可以用鼠标或者光标键高亮选择文本,不过输入任何字符的话,Vim 会用这个字符替换选择的高亮文本块,并且自动进入插入模式。

  1. 命令行模式(Command line mode)

在命令行模式中可以输入会被解释成并执行的文本。例如执行命令:键),搜索/?键)或者过滤命令!键)。
在命令执行之后,Vim 返回到命令行模式之前的模式,通常是普通模式。

  1. Ex 模式(Ex mode)

这和命令行模式比较相似,在使用 :visual 命令离开 Ex 模式前,可以一次执行多条命令

这其中我们常用到就是普通模式、插入模式和命令行模式,本课程也只涉及这三个常用模式的内容;

demo

``sh

1. 进入普通模式(默认模式)

$ vim ./test.md

supper user do / Linux 权限提升 ✅

$ sudo vim ./test.md


```sh
# 2. 按下 i/a 键,进入插入模式
# 编辑文本
# 3. 按下 Esc 键,进入命令行模式 (退出,强制退出 /保存退出,保存后强制退出)
# :q
# :q!
# :wq
# :wq!

https://www.lanqiao.cn/courses/2/learning/?id=16

demos

gif / video ???

pi@raspberrypi:~/Desktop $ pwd
/home/pi/Desktop

pi@raspberrypi:~/Desktop $ ls -all
总用量 60
drwxr-xr-x  2 pi   pi   4096  4月 13 11:37 .
drwxr-xr-x 17 pi   pi   4096  4月 13 11:37 ..
-rwxr-xr-x  1 pi   pi    174  4月 12 11:56 datetime.sh
-rw-r--r--  1 pi   pi      0  4月 13 11:32 five.log.txt
-rwxr-xr-x  1 pi   pi    267  4月 13 01:42 five.py
-rw-r--r--  1 pi   pi   2394  4月 13 12:30 gpio.log.txt
-rwxr-xr-x  1 pi   pi   1271  4月 13 01:11 gpio.py
-rw-r--r--  1 root root 1430  4月 13 12:04 gpio-sudo.log.txt
-rwxr-xr-x  1 pi   pi   1307  4月 13 00:32 gpio-sudo.py
-rw-r--r--  1 pi   pi   1452  4月 13 12:05 gpio-system.log.txt
-rwxr-xr-x  1 pi   pi   1309  4月 13 00:33 gpio-system.py
-rwxr-xr-x  1 pi   pi    207  4月 12 11:37 ip.sh
-rw-r--r--  1 pi   pi    693  4月 12 13:09 locale-datetime.py
-rw-r--r--  1 pi   pi     69  4月 13 03:40 ten.log.txt
-rwxr-xr-x  1 pi   pi    203  4月 13 00:13 test.py
-rwxr-xr-x  1 pi   pi    316  4月 12 23:49 time.py

pi@raspberrypi:~/Desktop $ vim gpio.py

# 普通模式(默认模式)
# 插入
# 可视
# 命令

image

refs

https://www.cnblogs.com/xgqfrms/p/13405977.html



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!