为什么 vim 中的某些命令需要冒号而有些则不需要? [英] Why some commands in vim require a colon while some don't?

查看:33
本文介绍了为什么 vim 中的某些命令需要冒号而有些则不需要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

vim 中的一些命令是通过首先输入冒号 (:) 给出的,例如 .:wq 用于保存文件和退出.虽然某些命令不需要冒号,例如替换命令 (R).我想知道这两种方法有什么区别?对于哪些需要冒号,哪些不需要,有什么具体规则吗?

Some of the commands in vim are given by first typing a colon (:) eg . :wq for saving a file and quitting . While some of the commands don't require a colon for example the Replace command (R). I want to know what is the difference between the two approaches ? Is there any specific rule as to which ones require a colon and which ones don't ?

推荐答案

你必须了解 vi 的历史,Vim的前身,做个说明.很久以前,当必须使用键盘和连接的打印机(称为终端)进行文本编辑时,没有鼠标,除了纸张之外没有其他显示器,因此几乎没有交互性.通过名为 ex 的编辑器,编辑由简短的助记命令组成.你发出了一条或几行的命令(例如 :substitute/foo/bar),编辑器服从了.如果您不确定命令的效果,您可以:print 一些行.

You have to look into the history of vi, the predecessor of Vim, for an explanation. A long time ago, when text editing had to be done with a keyboard and attached printer (called a terminal), there was no mouse, no display other than the paper, and therefore, little interactivity. Editing consisted of short, mnemonic commands via an editor called ex. You issued a command addressing one or several lines (e.g. :substitute/foo/bar), and the editor obeyed. In case you were not sure about the command's effects, you could :print some lines.

时间过去了,视频终端出现了,vi 编辑器合并了 ex 命令(因为它们很有用而且程序员已经习惯了),但引入了更多交互命令,如 delete(x)、插入 (i) 等.ex 命令在命令行模式下仍然可用,它以 : 开始,以 Enter 结束.

Time passed, video terminals appeared, and the vi editor incorporated the ex commands (because they were useful and the programmers were used to them), but introduced more interactive commands like delete (x), insert (i), and so on. The ex commands are still available in command-line mode, which is started with :, and concluded with Enter.

Vi 和 Vim 在这方面很特别,因为它们有这些不同的模式,其中相同的键意味着不同的东西,这取决于一个人所处的模式.要精通 Vim,你必须学习了解不同的模式,以及如何最好地利用它们来实现您的编辑目标.

Vi and Vim are special in this regard, because they have these different modes where the same keys mean different things depending on which mode one is in. To become proficient in Vim, you have to learn about the different modes, and how to best use them to achieve your editing goals.

:help vim-modes 为您提供了一个了解优秀而全面的帮助工具的起点.

:help vim-modes gives you a starting point into the excellent and comprehensive help facilities.

这篇关于为什么 vim 中的某些命令需要冒号而有些则不需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆