VIM命令集

Command Action Notes
vim file +54 open file and go to line 54 any : command can be run using + on command line
vim -O file1 file2 open file1 and file2 side by side  
Insert enter insert mode so you can start typing. Alternatively one can use i ora.
Esc leave insert mode so you can issue commands. Note in VIM the cursor keys & {Home, End, Page{up,down}} and Delete and Backspace work as expected in any mode, so you don‘t need to go back to command mode nearly as much as the origonal vi. Note even Ctrl+{left,right} jumps words like most other editors. Note also Ctrl+[ and Ctrl+c are equivalent to Esc and may be easier to type. Also Ctrl+o in insert mode will switch to normal mode for one command only and automatically switch back.
:command runs named command  
:help word shows help on word Typing Ctrl+d after word shows all entries containing word
:echo &word shows value of word  
windows
:e set buffer for current window you can optionally specify a new file or existing buffer number (#3 for e.g.). Note if you specify a directory a file browser is started. E.g. :e . will start the browser in the current directory (which can be changed with the :cd command).
:sp new window above ditto
:vs new window to left ditto
:q close current window  
:qa close all windows add trailing ! to force
Ctrl+w {left,right,up,down} move to window  
Ctrl+w Ctrl+w toggle window focus  
Ctrl+w = autosize windows to new terminal size for e.g.
:ba new window for all buffers ":vert ba" tiles windows vertically
buffers
:ls list buffers  
gf open file under cursor  
:bd delete buffer and any associated windows
:w save file Note :up[date] only writes file if changes made, but it‘s more awkward to type
:sav filename save file as filename Note :w filename doesn‘t switch to new file. Subsequent edits/saves happen to existing file
undo/redo
u undo  
Ctrl+r redo  
. repeat  
navigation
gg Goto start of file  
G Goto end of file  
:54 Goto line 54  
80| Goto column 80  
Ctrl+g Show file info including your position in the file
ga Show character info g8 shows UTF8 encoding
Ctrl+e scroll up Ctrl+x needed first for insert mode
Ctrl+y scroll down Ctrl+x needed first for insert mode
zt scroll current line to top of window  
w Goto next word Note Ctrl+{right} in newer vims (which work also in insert mode)
b Goto previous word Note Ctrl+{left} in newer vims
[{ Goto previous { of current scope  
% Goto matching #if #else,{},(),[],/* */ must be one on line
zi toggle folds on/off  
bookmarks
m {a-z} mark position as {a-z} E.g. m a
‘ {a-z} move to position {a-z} E.g. ‘ a
‘ ‘ move to previous position  
‘0 open previous file handy after starting vim
selection/whitespace
v select visually use cursor keys, home, end etc.
Shift+v line select CTRL+v = column select
Delete cut selection  
"_x delete selection without updating the clipboard or yank buffer. I remap x to this in my .vimrc
y copy selection  
p paste (after cursor) P is paste before cursor
"Ay append selected lines to register a use lowercase a to initialise register
"ap paste contents of a  
gq reformat selection justifies text and is useful with :set textwidth=70 (80 is default)
= reindent selection very useful to fix indentation for c code
> indent section useful with Shift+v%
< unindent section remember . to repeat and u to undo
:set list! toggle visible whitespace See also listchars in my .vimrc
clipboard shortcuts
dd cut current line  
yy copy current line  
D cut to end of line  
y$ copy to end of line  
search/replace
/regexp searches forwards for regexp ? reverses direction
n repeat previous search N reverses direction
* searches forward for word under cursor # reverses direction
:%s/1/2/gc search for regexp 1 and replace with 2 in file c = confirm change
:s/1/2/g search for regexp 1 and replace with 2 in (visual) selection  
programming
K lookup word under cursor in man pages 2K means lookup in section 2
:make run make in current directory  
Ctrl+] jump to tag Ctrl+t to jump back levels. I map these to Alt+?? in my .vimrc
vim -t name Start editing where name is defined  
Ctrl+{n,p} scroll forward,back through autocompletions for word before cursor uses words in current file (and included files) by default. You can change to a dictionary for e.g: set complete=k/usr/share/dicts/words Note only works in insert mode
Ctrl+x Ctrl+o scroll through language specific completions for text before cursor "Intellisense" for vim (7 & later). :help compl-omni for more info. Useful for python, css, javascript, ctags, ... Note only works in insert mode
external filters
:%!filter put whole file through filter  
:!filter put (visual) selection through filter  
:,!command replace current line with command output  
map <f9> :w<CR>:!python %<CR> run current file with external program  

(来源:http://www.pixelbeat.org/vim.tips.html

VIM命令集,布布扣,bubuko.com

时间: 2024-10-02 17:54:54

VIM命令集的相关文章

Vim命令合集

来源:Vim命令合集 命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filename 打开vim并创建名为filename的文件 文件命令 打开单个文件 vim file 同时打开多个文件 vim file1 file2 file3 ... 在vim窗口中打开一个新文件 :open file 在新窗口中打开文件 :split file 切换到下一个文件 :bn 切换到上一

[转载]VIM命令合集

Vim命令合集 http://www.cnblogs.com/softwaretesting/archive/2011/07/12/2104435.html 命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filename 打开vim并创建名为filename的文件 文件命令 打开单个文件 vim file 同时打开多个文件 vim file1 file2 file3 ..

Mysql 常用命令集

1.mysqlbinlog工具使用方法如下: 先使用 show binary logs 查看 在使用导出命令 mysqlbinlog -R -uroot -pxxxx -hxxx.xxx.xxx.xxx -d db_name  --base64-output=decode-rows  --start-datetime='2015-08-13 13:11:21'  --stop-datetime="2015-08-13 13:18:21" mysql-bin.000008 > my

KVM命令集管理虚拟机

使用KVM命令集管理虚拟机 查看虚拟机状态 [[email protected] ~]# virsh list --all Id 名称 状态 ---------------------------------------------------- 2 c01 running 虚拟机的关机与开机 [[email protected] ~]# virsh shutdown c01 域 c01 被关闭 [[email protected] ~]# virsh list --all Id 名称 状态 -

KVM命令集与优化

(一)使用KVM命令集管理虚拟机 1:KVM基本功能管理 (1)查看命令帮助 [[email protected] ~]# virsh -h virsh [options]... [<command_string>] virsh [options]... <command> [args...] .../省略部分内容 2:查看KVM的配置文件存放目录 [[email protected] ~]# ls /etc/libvirt/qemu CentOS7.4-x86_64.xml ne

5.5 进入编辑模式 5.6 vim命令模式 5.7 vim实践

5.5 进入编辑模式 5.6 vim命令模式 5.7 vim实践 扩展 vim的特殊用法 http://www.apelearn.com/bbs/thread-9334-1-1.html vim常用快捷键总结 http://www.apelearn.com/bbs/thread-407-1-1.html vim快速删除一段字符 http://www.apelearn.com/bbs/thread-842-1-1.html vim乱码 http://www.apelearn.com/bbs/thr

MHA 日常维护命令集

MHA 日常维护命令集 1.查看ssh登陆是否成功 masterha_check_ssh --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf 2.查看复制是否建立好 masterha_check_repl --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf 3.启动mha noh

Linux CentOS7 中vim命令的使用

一. vim介绍 vim 是vi 的升级版本:可带颜色显示 1. 安装vim yum install -y vim-enhancedvim /etc/passwd 2. 三种模式: 一般模式:dd p yy  编辑模式:编辑文件内容 命令模式::/ ? 二. vim颜色显示和移动光标 1. vim 可以根据文件的路径和名字显示颜色 cp /etc/passwd /tmp  vim /tmp/passwd 查看就无颜色 /etc 下会显示颜色,是他的特性.cp /etc/fstab /tmpvim

老男孩教育每日一题-2017年5月9日-vim命令粘贴带#号或注释信息格式会出现混乱情况怎么办

1.题目 老男孩教育每日一题-2017年5月9日-vim编辑器使用知识点:vim命令粘贴带#号或注释信息格式会出现混乱情况,有什么方法进行解决?问题说明:每次复制代码时,如果代码里有 //或# 这样的注释就容易让格式乱掉,显示的内容不整齐,并不是所期望的显示格式. 2.参考答案 原因分析: 是由于vim编辑命令的自动缩进功能所影响,因此粘贴带注释的代码时可以取消自动缩进 问题解决: vim在粘贴代码时会自动缩进,把代码搞得一团糟糕,甚至可能因为某行的一个注释造成后面的代码全部被注释掉:最初的解决