FakeVim 模式和命令
在FakeVim 模式下,主编辑器中的大部分按键都会被拦截,并以类似 Vim 的方式进行解释。大多数支持的命令后面都可以跟一个动作命令,或在可视化模式下执行,或与寄存器一起使用,或以重复次数为前缀。
下文将介绍在支持的模式下模拟的命令,以及它们在功能上与 Vim 的不同之处:
- 正常模式
- 可视化
- 命令行 (:)
- 插入和替换
有关使用 Vim 的更多信息,请参阅 Vim 网站上的文档。
正常模式和可视模式
- 基本移动,如
h/j/k/l
,<C-U>
,<C-D>
,<C-F>
,<C-B>
,gg
,G
,0
,^
、$
- 单词移动,如
w
,e
、b
- 内/外运动,如
ciw
,3daw
, ya{ f
和 运动t
[ and \c ]
移动- {段落移动
- 用寄存器删除/更改/延展/粘贴
- 撤销和重做
<C-A>
和 增加或减少十进制、八进制或十六进制格式的数字(例如, 在 上或 之前会更改为 )<C-X>
128<C-A>
"0x0ff"
"0x17f"
.
重复上次更改/search
,?search
,*
,#
,n
,N
- 除了\<
和\>
与 QRegExp 中的\b
相同外,大部分正则表达式语法都在 Vim 中使用。@
和 (宏记录和执行)特殊键保存为q
<S-Left>
- 标记
gv
转到最后一个可视化选择;如果在其周围编辑文本,则会有所不同- 缩进使用
=
,<<
,>>
,带有移动、计数功能,并在可视模式下使用 - 到上/下,如
~
,gU
、gu
i
,a
,o
,I
,A
, 和O
进入插入模式- 滚动窗口,如
zt
,zb
、zz
- 换行移动,如
gj
,gk
,g0
,g^
、g$
命令行模式
:map
,:unmap
,:inoremap
, 等等:source
源 vimrc 文件逐行:substitute
在一定范围内替换表达式:'<,'>!cmd
过滤外部命令(例如,用 对文件中的行排序):%!sort
:<range>sor[t][!]
:.!cmd
插入外部命令的标准输出:read
:yank
,:delete
、:change
:move
,:join
:20
转到一个地址:history
:registers
,:display
:nohlsearch
:undo
,:redo
:normal
:<
,:>
set formatoptions=
, 请参见 Vim 文档中的:h fo-table
。目前支持的字母fo-j
插入模式
<C-O>
执行单个命令并返回插入模式<C-V>
插入原始字符<insert>
切换替换模式
选项
使用:set ...
设置下表列出的选项:
长名称 | 短名称 | 参数 |
---|---|---|
autoindent | ai | |
backspace | bs | indent ,eol 、start |
blinkingcursor | bc | |
clipboard | cb | |
expandtab | et | |
hlsearch | hls | |
ignorecase | ic | |
incsearch | is | |
iskeyword | isk | 以下字符的组合:@ ,48-57 ,_ ,192-255 ,a-z 、A-Z |
relativenumber | rnu | |
scrolloff | so | |
shiftwidth | sw | |
showcmd | sc | |
smartcase | scs | |
smartindent | si | |
smarttab | sta | |
startofline | sol | |
tabstop | ts | |
tildeop | top | |
usecoresearch | ucs | |
wrapscan | ws |
Vimrc 示例
" highlight matched set hlsearch " case insensitive search set ignorecase set smartcase " search while typing set incsearch " wrap-around when searching set wrapscan " show pressed keys in lower right corner set showcmd " tab -> spaces set expandtab set tabstop=4 set shiftwidth=4 " keep a 5 line buffer for the cursor from top/bottom of window set scrolloff=5 " X11 clipboard set clipboard=unnamed " use ~ with movement set tildeop " mappings nnoremap ; : inoremap jj <Esc> " clear highlighted search term on space noremap <silent> <Space> :nohls<CR> " reselect visual block after indent vnoremap < <gv vnoremap > >gv " MOVE LINE/BLOCK nnoremap <C-S-J> :m+<CR>== nnoremap <C-S-K> :m-2<CR>== inoremap <C-S-J> <Esc>:m+<CR>==gi inoremap <C-S-K> <Esc>:m-2<CR>==gi vnoremap <C-S-J> :m'>+<CR>gv=gv vnoremap <C-S-K> :m-2<CR>gv=gv
另请参阅 Edit like in Vim和FakeVim。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.