ue编辑器 设置unix
Any UNIX system provides many different editors out of the box. In this section I will describe the most popular ones showing the basics of working with them. vim
and emacs
in particular have lots and lots of different commands, have plugins, and so you can spend years using them just scratching the surface of what’s possible.
任何UNIX系统都提供许多开箱即用的编辑器。 在本节中,我将描述最受欢迎的那些,展示与他们合作的基本知识。 特别是vim
和emacs
有很多不同的命令,有插件,因此您可以花费数年的时间使用它们,只是摸索了一切。
ed
(ed
)
ed
is the original UNIX text editor, and it’s the most basic you can work with. It’s also very rarely used, if ever used, by most people.
ed
是原始的UNIX文本编辑器,它是您可以使用的最基本的。 大多数人也很少使用(如果曾经使用过) 。
Run it by typing ed
. This starts an interactive session. Enter in write mode by typing a
on a single line, and press enter
. Then type everything you want, and once you are done, write just a dot (.
) on a line and press enter
.
输入ed
运行它。 这将启动一个交互式会话。 通过在一行上键入a
进入写入模式,然后按enter
。 然后键入您想要的所有内容,完成后,在一行上只写一个点( .
),然后按enter
键。
Now type w
followed by a file name to save the buffer to a file. It will return the number of bytes written to the file.
现在,键入w
然后输入文件名,以将缓冲区保存到文件中。 它将返回写入文件的字节数。
You can then press q
to quit.
然后,您可以按q
退出。
You can edit a file with ed
by invoking it with the file name: ed <filename>
. When you press a
to add, you add content to the bottom of the file.
您可以编辑与文件ed
与文件名调用它: ed <filename>
。 按a
进行添加时,将内容添加到文件的底部。
Inside an ed
session you can type ,p
to print the current file content.
在ed
会话中,您可以键入,p
以打印当前文件内容。
vi
/ vim
(vi
/ vim
)
vim
is a very popular file editor, especially among programmers. It’s actively developed and frequently updated, and there’s a very big community around it. There’s even a Vim conference!
vim
是一种非常流行的文件编辑器,尤其是在程序员中。 它是积极开发并经常更新的,并且周围有很大的社区。 甚至有一个Vim会议 !
vi
in modern systems is just an alias to vim
, which means vi
im
proved.
vi
在现代系统中只是一个别名vim
,该装置vi
我m
证明。
You start it by running vi
on the command line.
您可以通过在命令行上运行vi
来启动它。
You can specify a filename at invocation time to edit that specific file:
您可以在调用时指定文件名来编辑该特定文件:
vi test.txt
You have to know that Vim has 2 main modes:
您必须知道Vim有2种主要模式:
command (or normal) mode
命令 (或正常 )模式
insert mode
插入模式
When you start the editor, you are in command mode. You can’t enter text like you expect from a GUI-based editor. You have to enter insert mode. You can do this by pressing the i
key. Once you do so, the -- INSERT --
word appear at the bottom of the editor:
启动编辑器时,您处于命令模式。 您无法从基于GUI的编辑器中输入期望的文本。 您必须进入插入模式 。 您可以通过按i
键来执行此操作。 完成后,在编辑器的底部将显示-- INSERT --
单词:
Now you can start typing and filling the screen with the file contents:
现在,您可以开始输入文件内容并在屏幕上填充:
You can move around the file with the arrow keys, or using the h
- j
- k
- l
keys. h-l
for left-right, j-k
for down-up.
您可以使用箭头键或使用h
- j
- k
- l
键在文件中移动。 hl
代表左右, jk
代表向下。
Once you are done editing you can press the esc
key to exit insert mode, and go back to command mode.
完成编辑后,可以按esc
键退出插入模式,然后返回到命令模式 。
At this point you can navigate the file, but you can’t add content to it (and be careful which keys you press as they might be commands).
此时,您可以浏览文件,但是不能向其中添加内容(请注意按哪个键,因为它们可能是命令)。
One thing you might want to do now is saving the file. You can do so by pressing :
(colon), then w
.
您现在可能要做的一件事就是保存文件 。 您可以按:
冒号),然后按w
。
You can save and quit pressing :
then w
and q
: :wq
您可以按:
然后按w
和q
:wq
保存并退出。
You can quit without saving, pressing :
then q
and !
: :q!
您可以不保存就退出 ,按:
然后按q
和!
:q!
You can undo and edit by going to command mode and pressing u
. You can redo (cancel an undo) by pressing ctrl-r
.
您可以通过进入命令模式并按u
来撤消和编辑。 您可以通过按ctrl-r
重做 (取消撤消)。
Those are the basics of working with Vim. From here starts a rabbit hole we can’t go into in this little introduction.
这些是使用Vim的基础知识。 从这里开始一个兔子洞,在这个小介绍中我们不能介绍。
I will only mention those commands that will get you started editing with Vim:
我只会提及那些使您开始使用Vim进行编辑的命令:
pressing the
x
key deletes the character currently highlighted按
x
键删除当前突出显示的字符pressing
A
goes at the end of the currently selected line按
A
转到当前所选行的末尾press
0
to go to the start of the line按
0
转到行的开头go to the first character of a word and press
d
followed byw
to delete that word. If you follow it withe
instead ofw
, the white space before the next word is preserved转到单词的第一个字符,然后按
d
然后按w
删除该单词。 如果用e
而不是w
跟随它,则保留下一个单词之前的空白use a number between
d
andw
to delete more than 1 word, for example used3w
to delete 3 words forward使用
d
和w
之间的数字删除一个以上的单词,例如,使用d3w
向前删除3个单词press
d
followed byd
to delete a whole entire line. Pressd
followed by$
to delete the entire line from where the cursor is, until the end按
d
其次d
删除整个整条生产线。 按d
然后按$
以删除光标所在的整行,直到结尾
To find out more about Vim I can recommend the Vim FAQ and especially running the vimtutor
command, which should already be installed in your system and will greatly help you start your vim
explorations.
要了解有关Vim的更多信息,我可以推荐Vim FAQ ,尤其是运行vimtutor
命令,该命令应该已经安装在您的系统中,并且将大大帮助您开始进行vim
探索。
emacs
(emacs
)
emacs
is an awesome editor and it’s historically regarded as the editor for UNIX systems. Famously vi
vs emacs
flame wars and heated discussions caused many unproductive hours for developers around the world.
emacs
是一个了不起的编辑器,并且在历史上一直被视为UNIX系统的编辑器。 著名的vi
vs emacs
火焰之战和激烈的讨论对世界各地的开发人员造成了很多无用的时间。
emacs
is very powerful. Some people use it all day long as a kind of operating system (https://news.ycombinator.com/item?id=19127258). We’ll just talk about the basics here.
emacs
非常强大。 有人整日使用它作为一种操作系统( https://news.ycombinator.com/item?id=19127258 )。 我们将在这里讨论基础知识。
You can open a new emacs session simply by invoking emacs
:
您只需调用emacs
即可打开一个新的emacs会话:
macOS users, stop a second now. If you are on Linux there are no problems, but macOS does not ship applications using GPLv3, and every built-in UNIX command that has been updated to GPLv3 has not been updated. While there is a little problem with the commands I listed up to now, in this case using an emacs version from 2007 is not exactly the same as using a version with 12 years of improvements and change. This is not a problem with Vim, which is up to date. To fix this, run
brew install emacs
and runningemacs
will use the new version from Homebrew (make sure you have Homebrew installed)macOS用户,请立即停止。 如果您使用的是Linux,则没有问题,但是macOS不会使用GPLv3交付应用程序,并且尚未更新为已更新为GPLv3的每个内置UNIX命令。 尽管我到目前为止列出的命令存在一些问题,但是在这种情况下,使用2007年的emacs版本与使用经过12年改进和更改的版本并不完全相同。 这不是Vim的问题,它是最新的。 要解决此问题,请运行
brew install emacs
,运行emacs
将使用Homebrew的新版本(确保已安装Homebrew )
You can also edit an existing file calling emacs <filename>
:
您还可以编辑一个emacs <filename>
的现有文件:
You can start editing and once you are done, press ctrl-x
followed by ctrl-w
. You confirm the folder:
您可以开始编辑,一旦完成,请按ctrl-x
然后按ctrl-w
。 您确认文件夹:
and Emacs tell you the file exists, asking you if it should overwrite it:
然后Emacs告诉您该文件存在,并询问您是否应该覆盖它:
Answer y
, and you get a confirmation of success:
回答y
,您将确认成功:
You can exit Emacs pressing ctrl-x
followed by ctrl-c
. Or ctrl-x
followed by c
(keep ctrl
pressed).
您可以先按ctrl-x
再按ctrl-c
退出Emacs。 或按ctrl-x
然后按c
(按住ctrl
键)。
There is a lot to know about Emacs. More than I am able to write in this little introduction. I encourage you to open Emacs and press ctrl-h
r
to open the built-in manual and ctrl-h
t
to open the official tutorial.
关于Emacs有很多知识。 在这个小介绍中,我所能写的更多。 我鼓励您打开Emacs并按ctrl-h
r
打开内置手册,然后按ctrl-h
t
打开官方教程。
nano
(nano
)
nano
is a more beginner friendly editor.
nano
是对初学者更友好的编辑器。
Run it using nano <filename>
.
使用nano <filename>
运行它。
You can directly type characters into the file without worrying about modes.
您可以直接在文件中键入字符,而不必担心模式。
You can quit without editing using ctrl-X
. If you edited the file buffer, the editor will ask you for confirmation and you can save the edits, or discard them. The help at the bottom shows you the keyboard commands that let you work with the file:
您可以退出而无需使用ctrl-X
进行编辑。 如果您编辑了文件缓冲区,编辑器将要求您确认,然后可以保存或放弃编辑。 底部的帮助向您显示了用于处理文件的键盘命令:
pico
is more or less the same, although nano
is the GNU version of pico
which at some point in history was not open source and the nano
clone was made to satisfy the GNU operating system license requirements.
pico
大致相同,尽管nano
是pico
的GNU版本,在历史上某些时候它不是开源的,并且nano
克隆是为了满足GNU操作系统许可要求而制成的。
ue编辑器 设置unix