`

【转】程序员应该知道的100个Vim命令

    博客分类:
  • vim
vim 
阅读更多

:e filename Open filename  for edition
:w Save file
:q Exit Vim
:w! Exit Vim without saving

Search

/word Search word  from top to bottom
?word Search word  from bottom to top
/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
/<dddd> Search exactly 4 digits
/^n{3} Find 3 empty lines
:bufdo /searchstr/ Search in all open files

Replace

:%s/old/new/g Replace all occurences of old  by new  in file
:%s/old/new/gw 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 containstring
: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/r//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/^(.*)n1$/1/ Delete lines which appears twice
Ctrl+a Increment number under the cursor
Ctrl+x Decrement number under cursor
ggVGg? Change text to Rot13

Case

Vu Lowercase line
VU Uppercase line
g~~ Invert case
vEU Switch word to uppercase
vE~ Modify word case
ggguG Set all text to lowercase
: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

Read/Write files

: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

File explorer

:e . Open integrated file explorer
:Sex Split window and open integrated file explorer
: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

Interact with 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

Alignment

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

Tabs

: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

Window spliting

: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_ Maximise current window
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

Auto-completion

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

mk Marks current position as k
˜k Moves cursor to mark k
d™k Delete all until mark k

Abbreviations

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

Text indent

: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

Syntax highlighting

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

 

 

转载地址:http://my.oschina.net/leeming/blog/57857

 

 

分享到:
评论

相关推荐

    VIM命令大全图集

    VIM(Vi IMproved)是一款强大的文本编辑...总的来说,"VIM命令大全图集"这个资源对于学习和掌握VIM的各种操作非常有帮助。通过深入理解和实践这些命令,可以显著提升文本编辑效率,让编程和文件管理工作变得更加轻松。

    vim 命令 键盘图

    `vim命令图解.png`可能是详细解析各种Vim命令的图表,这些命令包括文本对象选择(如aw - 一个单词,ip - 一个句子),可视模式(`v`,`V`,`Ctrl + v`分别对应字符、行、块选择),以及文本操作(`.`重复上一次动作...

    vim命令壁纸改进

    2. **全屏适配**:优化的壁纸能完美适应各种屏幕比例,避免出现图像拉伸或压缩的情况,保证每个键位和对应的Vim命令都清晰可见。 3. **突出文字**:改进版壁纸对文字做了强化处理,可能采用了更鲜明的色彩对比,...

    Vim 常用命令

    下面详细介绍一些常用的Vim命令,帮助用户更高效地使用这一强大的工具。 首先,进入Vim的基本命令是`vim [filename]`,这会打开一个名为filename的文件。如果文件不存在,则会创建一个新文件。如果要打开文件的同时...

    vim 命令大全

    ### Vim命令大全与新手入门指南 #### 一、Vim简介与强大之处 Vim,全称Vi IMproved,是一款源自Unix系统下的Vi编辑器的高级版本,它不仅继承了Vi的强大功能,还在此基础上增加了许多改进和扩展,使之成为当今最...

    程序员的编辑器--VIM

    VIM主要由Bram Moolenaar开发,最初是在Amiga计算机上对一个名为Stevie的vi版本进行改进而来,之后逐步发展成为一个独立的编辑器。 VIM的一个重要特点是支持多级撤销功能,这是原始vi编辑器所不具备的。此外,VIM还...

    Vim命令手册(较全)

    《Vim命令手册》是Bram Moolenaar创作的一款强大的文本编辑器——Vim的详细使用指南。这本书由ZhaoRuFei翻译为中文,适用于Vim的7.2版本,是Linux用户和程序员不可或缺的参考资料。Vim,作为vi的增强版,以其高效、...

    VIM常见命令总结vim常见命令总结

    VIM(Vi IMproved)是一款强大的文本编辑器,深受程序员和系统管理员的喜爱。它提供了丰富的命令集,使得在没有图形用户界面的情况下也能高效地编辑文本。以下是对VIM常见命令的详细总结: 1. **启动与退出** - `...

    vim命令详细文档

    以下是对Vim命令的详细解读: 1. **打开文件操作**: - `vi filename`:打开名为`filename`的文件,如果文件不存在,Vim会创建新文件。 - `vi +n filename`:从文件的第`n`行开始编辑。 - `vi + filename`:从...

    vim实用技巧快速入门与速查手册

    Vim是一款非常强大的文本编辑器,它具有高度的可定制性,而且学习起来相对复杂,但它在程序员和系统管理员中非常受欢迎。以下是从给定文件内容中提取的知识点,涵盖Vim的基础使用技巧和高级功能。 1. Vim的几种模式...

    VIM常用命令大全

    本文档旨在详细介绍VIM中的常用命令,帮助用户更高效地使用这一工具。 #### 二、光标控制命令 光标控制是VIM中最基础的功能之一,熟练掌握这些命令能够极大提高编辑效率。 - **h**: 向左移动一个字符。 - **j**: 向...

    程序员的编辑器--VIM[定义].pdf

    【程序员的编辑器--VIM】是IT领域中程序员常用的一款强大的文本编辑器。VIM源自1976年Bill Joy开发的vi编辑器,它最初是为ex命令的可视化界面设计的,允许用户一次性查看一屏文本。随着时间的推移,VIM经过多次改进...

    含有vim常用命令的桌面背景图片

    **vim编辑器简介** vim(Vi IMproved)是一款强大的文本编辑器,它是vi(Visual Editor)的增强版,...将包含这些命令的壁纸作为桌面背景,无疑是一种很好的记忆辅助方式,可以在工作中随时查阅,提升vim操作技能。

    vim命令学习笔试总结总结总结

    ### vim命令学习笔试总结 在深入探讨vim命令之前,我们先来了解一下vim的基本概念及其重要性。Vim(Vi IMproved)是一款高级文本编辑器,它基于早期的vi编辑器进行了大量的改进和功能增强。Vim因其高效的操作、丰富...

    vim命令简表

    以上只是一部分基础和进阶的Vim命令,实际上Vim有着更为丰富的功能等待探索。通过深入学习和实践,你可以将Vim打造成一款极其高效的开发工具。记得查阅官方文档和在线资源,不断扩展你的Vim知识库。

    打造C程序员专用vim

    2. **安装cscope_maps.vim:** 由于cscope_maps.vim并不是一个独立的插件,而是包含了cscope功能增强脚本的文件,可以直接将其放置在`~/.vim/plugin/`目录下。 3. **生成cscope数据库:** 首先,需要确定cscope数据库...

    ubuntu vim命令

    ### Ubuntu下VIM命令详解及配置优化 #### VIM简介 VIM,全称为Vi IMproved,是一款在Unix系统及其衍生系统(如Linux)中广泛使用的文本编辑器。相较于其前身vi,VIM提供了更多的增强功能,如颜色支持、图形用户...

Global site tag (gtag.js) - Google Analytics