Linux Administration
medium

Questão de Linux Administration #019e3987

Enunciado da Questão
Linux Administration
#vi
#command-mode
#empty-buffer
#text-editor
Médio

What happens after issuing the command vi without any additional parameters?

A

vi starts and loads the last file used and moves the cursor to the position where vi was when it last exited.

B

vi starts and requires the user to explicitly either create a new or load an existing file.

C

vi exits with an error message as it cannot be invoked without a file name to operate on.

D

vi starts in command mode and opens a new empty file.

Correta
E

vi starts and opens a new file which is filled with the content of the vi buffer if the buffer contains text.

Explicação Oficial / Explicações da Comunidade

When vi is invoked without any parameters, it starts in command mode and opens a new empty file. This is the default behavior of the vi editor. The user is placed in command mode, where they can enter commands to manipulate text, but no file is loaded or created until the user explicitly writes to a filename using :w filename or saves and exits with :wq.

How it Works

  • The vi editor, upon startup without arguments, initializes an empty buffer. This buffer is not associated with any file on disk. The editor enters command mode, which is the default mode for vi. In command mode, keystrokes are interpreted as commands (e.g., i to enter insert mode, :w to write).
  • The user can then start typing by entering insert mode (e.g., pressing i), or execute commands like :e filename to load an existing file.

Why the Correct Value is Right

  • The statement "vi starts in command mode and opens a new empty file" accurately describes the behavior. The vi editor always starts in command mode, and without a filename, it opens an empty buffer.

Why the Incorrect Values are Wrong

  • The option suggesting that vi loads the last file used and moves the cursor to the previous position is incorrect. That behavior is specific to the vim editor when configured with certain settings (e.g., viminfo), but not default vi.
  • The option claiming vi requires the user to explicitly create or load a file is misleading. While the user must eventually specify a file to save, vi does not prompt or require immediate action; it simply presents an empty buffer.
  • The option stating vi exits with an error is false. vi can be invoked without arguments and will run normally.
  • The option claiming vi opens a new file filled with the content of the vi buffer is incorrect. The buffer is empty on startup; there is no pre-existing buffer content unless a previous session was saved with a viminfo file (again, not default vi).