如何使用VI编辑器在UNIX中的多个文件之间切换?

发布于 2024-12-18 21:12:59 字数 165 浏览 4 评论 0原文

我是 UNIX 新手。我正在使用 VI 编辑器进行 C 编程。 如果我使用 VI 编辑器一次打开多个文件,

vi *.c

我只能编辑第一个文件。如果我按“:wq”,它会显示有:“还有 6 个要编辑的文件”

如何在这些文件之间切换?

I'm new to UNIX. I am using VI editor to code for C programming.
If I open multiple files at a time using VI editor like,

vi *.c

I can edit the first file only. If I press ":wq", it shows me that there are: "6 more files to edit"

How can I switch between those files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

如梦亦如幻 2024-12-25 21:12:59

下一个文件::n

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

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

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

Next file: :n

Previous file: :p, :N or :prev depending on which vi implementation you're using.

Here's a typical cheat sheet which has a section "Files" on this topic.

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

恰似旧人归 2024-12-25 21:12:59

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

For Linux Red-Hat VI version 7.2.411 use :n and :N to switch next and previous.

一影成城 2024-12-25 21:12:59

AIX 的 vi 有它自己的命令;我花了一段时间才找到这些信息,因为这个问题的答案还没有,所以我会添加这个答案。

:p:N:prev 都无法转到上一个文件,您需要使用 < 的变体之一code>:n --- 命令。

移动到下一个文件的 :n 是相同的

使用 :n file_name 移动到某个文件(也可以用这种方式打开新文件)(要转到前一个文件,只需使用前一个文件的名称

即可使用 :n 文件名列表 定义要编辑的新文件列表(在本例中,文件 listof文件以及运行 :n 文件名列表后,将使用 :n 连续打开 names

手册页中的其他有用结果

   :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.

AIX's vi has it's own commands; it took me a while to find this information because the answers in this question didn't have it already, so I'll add this answer.

Neither :p, :N, nor :prev work to go to the previous file, you need to use one of the variations of the :n --- command.

The :n for moving to the next file is the same

Use :n file_name to move to a certain file (Can open new files this way too) (To go to the previous file, just do this with the previous file's name

Use :n list of file names to define a new list of files to edit (In this case, the files list, of, file, and names would be opened in series using :n after running :n list of file names

Other useful results from the man pages

   :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.
晒暮凉 2024-12-25 21:12:59

再加上两个,:first & :last

ig:

~# vi foo*.c


:n

Next File

:N

Last File

:b1

:first

First File

:last

Last File

:b#

`#` switch to buffer `N` file

plus two more, :first & :last

ig:

~# vi foo*.c


:n

Next File

:N

Last File

:b1

:first

First File

:last

Last File

:b#

`#` switch to buffer `N` file
昔日梦未散 2024-12-25 21:12:59

:b# 正在 vi 编辑器中打开特定文件,当打开多个文件时,# 表示此处的数字

:b# is working in vi editor to open particular file, when multiple files are opened, # means numbers here

披肩女神 2024-12-25 21:12:59

:e# 其中 # 是文件编号

:e# where # is the file number

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文