Skip to content

What is vim Linux command?

The Linux vim command is a versatile text editor popular among programmers for its powerful functionalities. It allows users to edit files directly in the terminal, offering features such as syntax highlighting, search and replace, multiple buffers, and more, making it a preferred choice for efficient text editing.

Terminal window
vim [options] [file]
OptionDescription
-cExecute the following command
-pOpen multiple files in tabs
-iIgnore .vimrc file
-uUse a specific .vimrc file
-ROpen the file in read-only mode
ParameterDescription
fileThe file to open/edit with vim
Terminal window
vim newfile.txt

Opens the vim editor to create a new file named “newfile.txt”.

Terminal window
vim existingfile.txt

Opens the vim editor to edit an existing file named “existingfile.txt”.

Terminal window
vim existingfile.txt

After opening a file in vim, use arrow keys and editors commands to navigate and edit text.

Terminal window
:wq

Saves the changes made in the file and exits the vim editor.

Terminal window
:q!

Discards any changes made in the file and exits the vim editor without saving.

To install the vim command in bash, run the following command:

Terminal window
sudo apt install vim

To open a file named “example.txt” using vim, use the following command:

Terminal window
vim example.txt

To save changes and exit vim, follow these steps:

  1. Press Esc key to ensure you are in normal mode.
  2. Type :wq and press Enter to save and exit.

To exit vim without saving changes, follow these steps:

  1. Press Esc key to ensure you are in normal mode.
  2. Type :q! and press Enter to force exit without saving.

To switch to insert mode in vim, follow these steps:

  1. Press Esc key to ensure you are in normal mode.
  2. Press i to enter insert mode and start typing.

To undo the most recent change in vim, press u while in normal mode.

To search for the text “search_term” in the file you are editing in vim, use the following command:

Terminal window
/search_term

How do I move to the beginning or end of a line in vim?

Section titled “How do I move to the beginning or end of a line in vim?”

To move to the beginning of a line, press 0 in normal mode. To move to the end of a line, press $ in normal mode.

  • Creating and editing plain text files
  • Writing and editing code in various programming languages
  • Configuring system files and scripts
  • Viewing and making changes to configuration files
  • Customizing text editing experience with plugins and custom settings