在使用VI编辑器时,如何在多个文件之间切换?

35

我是UNIX新手。我正在使用VI编辑器编写C程序。如果我像下面这样同时打开多个文件:

vi *.c
我只能编辑第一个文件。如果我按“:wq”,它会显示还有“6个文件要编辑”。 如何在这些文件之间切换?
6个回答

59

下一个文件::n

上一个文件::p:N:prev取决于使用的vi实现。

这是一个典型的备忘单,其中有一个关于“文件”主题的部分。

http://www.lagmonster.org/docs/vi2.html


5

对于Linux Red-Hat VI版本7.2.411,使用:n和:N来切换到下一个和上一个。


也适用于Mac OS X(它是BSD)。不确定“真正的”BSD vi。 - Christopher Schultz

2
AIX的vi有自己的命令。这些命令花了我一些时间才找到,因为此问题中的答案没有提供,所以我会添加这个答案。要返回上一个文件,既不能使用:p、:N或:prev,而需要使用:n ---命令的变体之一。移动到下一个文件的命令是相同的,使用:n file_name可以移动到特定文件(也可以通过此方式打开新文件)。要返回上一个文件,只需使用前一个文件的名称执行此操作。使用:n list of file names定义要编辑的新文件列表(在这种情况下,运行:n list of file names后,使用:n依次打开文件list、of、file和names)。man页面提供了其他有用的结果。
   :e File
        Edits the specified file. If you are using this subcommand 
        from the ex editor, you do not need to type the : (colon).
   :e!
        Re-edits the current file and discards all changes.
   :e + File
        Edits the specified file starting at the end.
   :e + Number File
        Edits the specified file starting at the specified line number.
   :e #
        Edits the alternate file. The alternate file is usually the 
        previous file name before accessing another file with a 
        :e command. However, if changes are pending on the current 
        file when a new file is called, the new file becomes the 
        alternate file. This subcommand is the same as the Ctrl-A 
        subcommand.
   Ctrl-G
        Shows the current file name, current line number, number of 
        lines in the file, and percentage of the way through the 
        file where the cursor is located.

2

再加两个:first和:last

例如:

~# vi foo*.c


:n

Next File

:N

Last File

:b1

:first

First File

:last

Last File

:b#

`#` switch to buffer `N` file

1
# 是在 vi 编辑器中打开特定文件时使用的数字,当多个文件被打开时。

-1

:e# 其中 # 为文件号码


1
创建一个名为“#”(无论您在那里放置的数字)的文件。 - Catskul

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接