乐闻世界logo
搜索文章和话题

How to exit from vi editors?

1个答案

1

To exit the vi editor, you can choose different commands based on your specific needs.

  1. If you simply want to exit the vi editor without making any changes to the file or saving modifications, you can use:

    shell
    :q!

    This command forces you to exit without saving changes.

  2. If you have made changes to the file and want to save them before exiting, you can use:

    shell
    :wq

    or

    shell
    :x

    Both commands save your changes and exit the vi editor. :wq stands for 'write and quit', while :x is a shorthand for 'save and exit'.

  3. If you only want to save changes without exiting the vi editor, you can use:

    shell
    :w

    Then, if you decide to exit, you can use:

    shell
    :q

These are the basic exit commands, which you can choose based on different situations. For example, in a project I worked on where I frequently modified configuration files, I typically used :wq to ensure changes were saved promptly and safely exited the editor, avoiding data loss.

2024年8月14日 13:11 回复

你的答案