`
天梯梦
  • 浏览: 13634345 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

130个你需要了解的VIM命令

 
阅读更多

基础

:e filename Open filename for edition
:w Save file
:q Exit Vim
:q! Quit without saving
:x Write file (if changes has been made) and exit
:sav filename Saves file as filename
. Repeats the last change made in normal mode
5. Repeats 5 times the last change made in normal mode

 

在文件中移动

k or Up Arrow move the cursor up one line
j or Down Arrow move the cursor down one line
e move the cursor to the end of the word
b move the cursor to the begining of the word
0 move the cursor to the begining of the line
G move the cursor to the end of the line
gg move the cursor to the begining of the file
L move the cursor to the end of the file
:59 move cursor to line 59. Replace 59 by the desired line number.
20| move cursor to column 20.
% Move cursor to matching parenthesis
[[ Jump to function start
[{ Jump to block start

 

剪切、复制和粘贴

y Copy the selected text to clipboard
p Paste clipboard contents
dd Cut current line

yy

nyy

Copy current line

将当前行向下n行复制到缓冲区,也可以用 "anyy 复制,"a 为缓冲区,a也可以替换为a到z的任意字母,可以完成多个复制任务。

y$ Copy to end of line
D Cut to end of line

 

搜索

/word Search word from top to bottom
?word Search word from bottom to top
* Search the word under cursor
/\cstring Search STRING or string, case insensitive
/jo[ha]n Search john or joan
/\< the Search the, theatre or then
/the\> Search the or breathe
/\< the\> Search the
/\< ¦.\> Search all words of 4 letters
/\/ Search fred but not alfred or frederick
/fred\|joe Search fred or joe
/\<\d\d\d\d\> Search exactly 4 digits
/^\n\{3} Find 3 empty lines
:bufdo /searchstr/ Search in all open files
bufdo %s/something/somethingelse/g Search something in all the open buffers and replace it withsomethingelse

 

替换

:%s/old/new/g Replace all occurences of old by new in file
:%s/onward/forward/gi Replace onward by forward, case unsensitive
:%s/old/new/gc Replace all occurences with confirmation
:2,35s/old/new/g Replace all occurences between lines 2 and 35
:5,$s/old/new/g Replace all occurences from line 5 to EOF
:%s/^/hello/g Replace the begining of each line by hello
:%s/$/Harry/g Replace the end of each line by Harry
:%s/onward/forward/gi Replace onward by forward, case unsensitive
:%s/ *$//g Delete all white spaces
:g/string/d Delete all lines containing string
:v/string/d Delete all lines containing which didn’t contain string
:s/Bill/Steve/ Replace the first occurence of Bill by Steve in current line
:s/Bill/Steve/g Replace Bill by Steve in current line
:%s/Bill/Steve/g Replace Bill by Steve in all the file
:%s/^M//g Delete DOS carriage returns (^M)
:%s/\r/\r/g Transform DOS carriage returns in returns
:%s#<[^>]\+>##g Delete HTML tags but keeps text
:%s/^\(.*\)\n\1$/\1/ Delete lines which appears twice
Ctrl+a Increment number under the cursor
Ctrl+x Decrement number under cursor
ggVGg? Change text to Rot13

 

大小写

Vu Lowercase line
VU Uppercase line
g~~ Invert case
vEU Switch word to uppercase
vE~ Modify word case
ggguG Set all text to lowercase
gggUG Set all text to uppercase
:set ignorecase Ignore case in searches
:set smartcase Ignore case in searches excepted if an uppercase letter is used
:%s/\<./\u&/g Sets first letter of each word to uppercase
:%s/\<./\l&/g Sets first letter of each word to lowercase
:%s/.*/\u& Sets first letter of each line to uppercase
:%s/.*/\l& Sets first letter of each line to lowercase

 

读写文件

:1,10 w outfile Saves lines 1 to 10 in outfile
:1,10 w >> outfile Appends lines 1 to 10 to outfile
:r infile Insert the content of infile
:23r infile Insert the content of infile under line 23

 

文件浏览器

:e . Open integrated file explorer
:Sex Split window and open integrated file explorer
:Sex! Same as :Sex but split window vertically
:browse e Graphical file explorer
:ls List buffers
:cd .. Move to parent directory
:args List files
:args *.php Open file list
:grep expression *.php Returns a list of .php files contening expression
gf Open file name under cursor

 

和 Unix 系统交互

:!pwd Execute the pwd unix command, then returns to Vi
!!pwd Execute the pwd unix command and insert output in file
:sh Temporary returns to Unix
$exit Retourns to Vi

 

对齐

:%!fmt Align all lines
!}fmt Align all lines at the current position
5!!fmt Align the next 5 lines

 

Tabs/Windows

:tabnew Creates a new tab
gt Show next tab
:tabfirst Show first tab
:tablast Show last tab
:tabm n(position) Rearrange tabs
:tabdo %s/foo/bar/g Execute a command in all tabs
:tab ball Puts all open files in tabs
:new abc.txt Edit abc.txt in new window

 

分屏显示

:e filename Edit filename in current window
:split filename Split the window and open filename
ctrl-w up arrow Puts cursor in top window
ctrl-w ctrl-w Puts cursor in next window
ctrl-w_ Maximize current window vertically
ctrl-w| Maximize current window horizontally
ctrl-w= Gives the same size to all windows
10 ctrl-w+ Add 10 lines to current window
:vsplit file Split window vertically
:sview file Same as :split in readonly mode
:hide Close current window
:­nly Close all windows, excepted current
:b 2 Open #2 in this window

 

自动完成

Ctrl+n Ctrl+p (in insert mode) Complete word
Ctrl+x Ctrl+l Complete line
:set dictionary=dict Define dict as a dictionnary
Ctrl+x Ctrl+k Complete with dictionnary

 

Marks

m {a-z} Marks current position as {a-z}
‘ {a-z} Move to position {a-z}
Move to previous position

 

缩写

:ab mail mail@provider.org Define mail as abbreviation of mail@provider.org

 

文本缩进

:set autoindent Turn on auto-indent
:set smartindent Turn on intelligent auto-indent
:set shiftwidth=4 Defines 4 spaces as indent size
ctrl-t, ctrl-d Indent/un-indent in insert mode
>> Indent
<< Un-indent
=% Indent the code between parenthesis
1GVG= Indent the whole file

 

语法高亮

:syntax on Turn on syntax highlighting
:syntax off Turn off syntax highlighting
:set syntax=perl Force syntax highlighting

 

转载请注明:程序猿 » 130个你需要了解的VIM命令

 

 

分享到:
评论

相关推荐

    vim命令详解

    本文档详细介绍了VIM下的各种命令,如何高效的使用vim,是读者对vim有一个大致的了解和基本的掌握。

    vim+命令大全

    vim,命令大全,有利于了解vim的相关命令。

    vim手册中7.2

    。读者可以通过本章来了解本手册是如何解释 Vim 命令的。 手册的两个部分 Vim 的手册分成两个部分: 1.... 参考手册 详细描述 Vim 的每一个命令的详细资料。 本手册大部分内容都假定 Vim 已经被正常安装了

    vim使用进阶 使用vim提高你的文本编辑效率

     本系列文章介绍我自己使用vim的一些经验,主要包括vim使用技巧、vim配置、vim命令、vim 插件等内容。本篇是序言,务虚为主。  在使用vim进行软件开发之前,我使用的工具是Source Insight,相信大家并不陌 生。...

    Learn-Vim_zh_cn-快乐快速学习Vimr

    Vim 难学难用?但事实是,它依旧受许多程序员的欢迎。...下面文件描述讲解VIm的简单语法规则,将 Vim 命令的一般结构,分解成了一个简单语法规则。一旦了解了 Vim 命令类似语法的结构,就能跟它「畅谈无阻」。

    Linux基础命令和VIM文本编辑器的基本使用

    简单的Linux基本命令的应用和vim文本编辑器的基本使用。

    PacVim一个教你vim命令的游戏。-C/C++开发

    PacVim是一款教您vim命令的游戏。 您必须移动pacman(绿色光标)以突出显示游戏板...我没有找到一种有趣的免费方法来深入了解vim命令,因此PacVim诞生了。 受经典PacMan的启发,PacVim是一款可以给任何人大量练习的游戏

    Vim实用技巧

    在学习 Vim 的初期,人们的确需要经历一段驼峰似的阻力,然而一旦完成了 vimtutor 的训练,并了解如何为 vimrc 配置一些基本选项后,就会达到一个新的高 度,能用 Vim 完成实际工作了—尽管步履蹒跚,但终有回报。 接下来...

    fzf.vim:fzf vim

    本身不是Vim插件,官方存储库仅提供Vim的,并且用户可以自行编写自己的Vim命令。 但是,我了解到,许多fzf用户不熟悉Vimscript,并且正在寻找可以在替代Vim插件中找到的功能的“默认”实现。 该存储库是从我的提取...

    openvim:Vim的交互式教程

    OpenVim是一个基于Web的项目,使人们可以快速了解Vim是什么编辑器。 Vim被认为是非常有用的,但一开始会感觉极不透明。 希望本教程可以使人们感到更轻松地给它一个机会。 OpenVim基于可解释vim命令的自定义引擎。 ...

    dash.vim:从Vim搜索Dash.app

    dash.vim 这个Vim插件将使用出色的搜索术语,从而使API查找变得简单。 它提供了新的:Dash命令和(推荐)映射系列。 警告: 是仅适用于Mac的应用程序,因此您将无法从在Linux或Windows上使用dash.vim中受益。 可以将...

    vim-php-cs-fixer, 使用 friendsofphp/php CS修正器.zip

    vim-php-cs-fixer, 使用 friendsofphp/php CS修正器 Vim-php-cs-fixer 集成 php-cs-fixer 。这个插件将在目录或者文件( ...取决于你调用的命令) 上执行 php-cs-fixer 命令。 查看选项以了解如何自定义。可用的选项:" If

    nord-vim-light:个人vim灯光主题

    要自动下载并激活Nord Vim,请按照和将Plug 'arcticicestudio/nord-vim'到vim-plug的插件加载函数中的中在Vim中运行:PlugInstall命令通过在添加colorscheme nord激活主题,或通过运行:colorscheme nord即时更改主题...

    vim-Grammalecte:语法语法检查器的vim插件

    Vim-Grammalecte是一个将Grammalecte集成到Vim中的插件。 Grammalecte是法语的开源语法检查器。 有关Grammalecte的更多详细信息,请参见 。 屏幕截图 如果您没有时间阅读帮助文件,此屏幕截图将使您了解...

    vimrc:一个简单有效的vim配置

    vim 的看法,请转到 要查看其他程序员喜欢使用哪些快捷方式,请访问 要了解有关 vim 可以做什么的更多信息,请访问 [The Vim 编辑器:Vim 可以做什么] ( ) 要查看.vimrc的介绍,请转到安装: 在安装之前,确保你有 ...

    vim vax 快捷键大全

    你会发现,在你越来越了解VIM之后,你就会花越来越少的时间使用插入模式了。 使用 h,j,k,l 使用VIM高效率编辑的第一步,就是放弃使用箭头键。使用VIM,你就不用频繁的在箭头键和字母键之间移来移去了,这会节省你...

    jedi-vim:对VIM使用jedi自动完成库

    jedi-vim-VIM很棒的Python自动补全功能 jedi-vim是绑定到自动完成库的VIM。 这是一些图片: 完成几乎所有内容(Ctrl +空格键)。... 除此之外,jedi-vim支持以下命令 完成 Goto分配&lt;leader&gt;g (典型

    ghpr-blame.vim:Vim插件,类似于`git-blame`,但用于GitHub上的拉取请求

    在Vim上的文件中责备拉取请求是一个Vim插件,用于研究哪个请求请求修改了哪一行。 就像git-blame ,但是git-blame显示了哪一行被哪个commit修改了。 这个Vim插件的灵感来自。用法1.在文件中运行:GHPRBlame 通过运行:...

    ubuntu下gcc编程入门

    如果你需要编译 Fortran 程序,那么还需要安装 gfortran(或 g77) sudo apt-get install gfortran 如果你已经了解一些 vim 的知识,而且想用它来编辑源代码,那么我们不妨装个完整版 sudo apt-get install vim-...

    vim-buftabline:忘记Vim标签了-现在您可以拥有缓冲标签了

    茶碱一个高度集成的,低配置的缓冲区列表,位于列表行中缓冲区基础如果您对缓冲区一无所知,那么您至少需要知道Vim中的缓冲区本质上就是一个文件,如果您设置了hidden ,Vim可以使文件保持打开状态,而不必在屏幕上...

Global site tag (gtag.js) - Google Analytics