http://vim.wikia.com/wiki/Using_command-line_history

---------------------------------------------------------------------------------

in:

Using command-line history

 

 
Tip 45 Printable Monobook Previous Next

created 2001 · complexity basic · version 5.7


When you press : to enter a command, or / to start a search, you often want to edit a previous command or search. That can be done using the up and down arrow keys to scroll through the history. Then you can edit a previous line. :help :

For example, type :s and then press the up arrow key. The last command that starts with exactly what you typed will be displayed. Scroll through the history by pressing up or down. There is a history for commands, and another for searches (and more :help history). You can list the entire history using the :history command (:help :history). The command :his lists the command history, and :his / lists the search history.

In many situations, a better solution is the command-line window which you can open in two ways:

  • Type q: for commands, or q/ for searches; or
  • Type : or / to start entering a command or search, then press the 'cedit' key (default is Ctrl-f :help 'cedit').

The advantage of the command-line window is that you can use all Vim's editing power, including searching with '/' in normal mode, or using whole-line completion (:help compl-whole-line) in insert mode. After editing a command, you can:

  • Press Enter to execute the current line (and close the command-line window); or
  • Press Ctrl-c twice to close the command-line window (cancel).

Contents

[show]

DetailsEdit

Suppose you search for "horse", then for "Hello", then for "helium", then for "habit".

If you type /h and repeatedly press up arrow, you will see /habit, then /helium, then /horse ("Hello" is skipped because the history navigation is case-sensitive and "Hello" does not start with a lowercase "h").

Register : holds the last command, and / holds the last search. Therefore ":p will paste the last command, and "/p will paste the last search.

Type @: to repeat the last command.

You may have used several commands (for example, :%s/old/new/g) on the current buffer, and now find you would like to repeat those commands on another buffer. Type q: to enter the command window, then select and yank the commands you want. Press Ctrl-c twice to close the command window. If wanted, you can paste the commands into a buffer, then edit and save them. Later, you can source the file containing the commands, or you can yank the commands, then type :@"<CR> to execute the yanked commands on the current buffer.

If you always want to use the command editing window, try these mappings:

nnoremap : q:i
nnoremap / q/i
nnoremap ? q?i
 
 

Keeping the window openEdit

Executing a command closes the window but sometimes you want it to remain open.

Under :help q: we find a suggestion to map a key such as F5 to execute the current line, then re-open the command window: :autocmd CmdwinEnter * nnoremap <buffer> <F5> <CR>q:

This can be expanded to put us back on the same line in the command window, which is useful when repeating a whole series of commands. We use a global variable to remember which line we were on (buffer-local variables are lost when the window closes).

:autocmd CmdwinEnter * nnoremap <buffer> <F5> :let g:CmdWindowLineMark=line(".")<CR><CR>q::execute "normal ".g:CmdWindowLineMark."G"<CR>

ReferencesEdit

CommentsEdit

 TO DO 

  • The standard way to close the command-line window is with :q, or <C-W>q, or any of the standard "close this window" commands --- not with double Ctrl-C.
  • What is the history file called? Where is it stored?
The command window is not associated with a file at all. It is populated at startup from the .viminfo file, however. That may be worth mentioning somewhere...and the option to disable this

vim高级用法的更多相关文章

  1. 使用wget做站点镜像及wget的高级用法

    本文为大家介绍 使用wget做站点镜像及wget的高级用法,供大家学习参考. # wget -r -p -np -k http://xxx.edu.cn -r 表示递归下载,会下载所有的链接,不过要注 ...

  2. vim/vi用法总结

    第一章:安装: 在命令行运行vim,如果找不到程序,需要自己安装. 1.1 下载 从官方网站ftp://ftp.vim.org/pub/vim/unix/中选择一个版本下载,我这里使用的是vim-7. ...

  3. redis的Linux系统安装与配置、redis的api使用、高级用法之慢查询、pipline事物

    今日内容概要 redis 的linux安装和配置 redis 的api使用 高级用法之慢查询 pipline事务 内容详细 1.redis 的linux安装和配置 # redis 版本选择问题 -最新 ...

  4. Visual Studio 宏的高级用法

    因为自 Visual Studio 2012 开始,微软已经取消了对宏的支持,所以本篇文章所述内容只适用于 Visual Studio 2010 或更早期版本的 VS. 在上一篇中,我已经介绍了如何编 ...

  5. SolrNet高级用法(分页、Facet查询、任意分组)

    前言 如果你在系统中用到了Solr的话,那么肯定会碰到从Solr中反推数据的需求,基于数据库数据生产索引后,那么Solr索引的数据相对准确,在电商需求中经常会碰到菜单.导航分类(比如电脑.PC的话会有 ...

  6. sqlalchemy(二)高级用法

    sqlalchemy(二)高级用法 本文将介绍sqlalchemy的高级用法. 外键以及relationship 首先创建数据库,在这里一个user对应多个address,因此需要在address上增 ...

  7. Solr学习总结(六)SolrNet的高级用法(复杂查询,分页,高亮,Facet查询)

    上一篇,讲到了SolrNet的基本用法及CURD,这个算是SolrNet 的入门知识介绍吧,昨天写完之后,有朋友评论说,这些感觉都被写烂了.没错,这些基本的用法,在网上百度,资料肯定一大堆,有一些写的 ...

  8. 再谈Newtonsoft.Json高级用法

    上一篇Newtonsoft.Json高级用法发布以后收到挺多回复的,本篇将分享几点挺有用的知识点和最近项目中用到的一个新点进行说明,做为对上篇文章的补充. 阅读目录 动态改变属性序列化名称 枚举值序列 ...

  9. Jquery remove 高级用法

    Jquery remove 高级用法 html 代码 <div class="file-image">abc1111</div><div class= ...

随机推荐

  1. php开发之命名规则

    类命名 1.使用大写的字母作为词的切割,其它字母均使用小写字母 2.名字的首字母使用大写字母 3.不要使用下划线"_" 类属性的命名 1.属性的命名应该以'm'为前缀 2.前缀'm ...

  2. android编译错误“OnClickListener cannot be resolved to a type”

    在android代码编译时可能会出现如下错误: 部分代码: <span style="font-size:18px;">public void onCreate(Bun ...

  3. Windows Phone本地数据库(SQLCE):2、LINQ to SQL(翻译)(转)

    首先.要说到的是,windows phone 7.1上基本的数据库功能是SQL Compact关于Mango的一个实现,使用linq to sql访问存储在数据库上的数据.   1.LINQ to S ...

  4. Java异常(二) 《Effective Java》中关于异常处理的几条建议

    概要 本章是从<Effective Java>摘录整理出来的关于异常处理的几条建议.内容包括:第1条: 只针对不正常的情况才使用异常第2条: 对于可恢复的条件使用被检查的异常,对于程序错误 ...

  5. mysql 和 sqlite 区别 及 SQLite Expert Professional sqliteManager 区别

    mysql 和 sqlite 区别 SQLITE是单机数据库.功能简约,小型化,追求最大磁盘效率MYSQL是完善的服务器数据库.功能全面,综合化,追求最大并发效率 MYSQL.Sybase.Oracl ...

  6. 升级WINDOWS10后任务栏的图标老是闪动是怎么回事

    解决方法:1.进入设置→更新和安全→恢复2.找到高级启动,点击“立即重启3.重启后,进入第一个选择画面,点击“疑难解答”4.然后点击“高级选项”5.在其中选择“启动设置”6.这里给出了下次重启后的主要 ...

  7. 【nginx】配置Nginx实现负载均衡

    一文中已经提到,企业在解决高并发问题时,一般有两个方向的处理策略,软件.硬件,硬件上添加负载均衡器分发大量请求,软件上可在高并发瓶颈处:数据库+web服务器两处添加解决方案,其中web服务器前面一层最 ...

  8. JKS和PFX文件相互转换方法

    JKS(JavaKeysotre)格式和PFX(PKCS12)格式,是最常见的SSL证书格式文件,可以包含完整的证书密钥对,证书链和信任证书信息.PFX常用于Windows IIS服务器,JKS常用语 ...

  9. Maven内置属性及使用

    Maven共有6类属性: 内置属性(Maven预定义,用户可以直接使用) ${basedir}表示项目根目录,即包含pom.xml文件的目录; ${version}表示项目版本; ${project. ...

  10. SRE学习笔记:分布式共识系统、Paxos协议

    最近阅读了<SRE Google运维解密>的第23章,有一些感触,记录一下. 日常工作中,我们经常需要一些服务分布式的运行.跨区域如跨城.跨洲部署运行分布式系统往往是容易的,但是如何保证各 ...