- What is Vim?
Answer: Vim, short for Vi Improved, is a highly configurable, powerful, and widely used text editor, primarily designed for Unix-like operating systems.
Explanation: Vim is an enhanced version of the traditional Unix text editor vi, offering several additional features, plugins, and customization options.
- How can you enter the Vim command mode from the normal mode?
Answer: By pressing the colon (:) key.
Explanation: In Vim, the command mode allows you to enter commands to perform various tasks, such as saving files, searching, replacing, and executing scripts.
- Which command saves the current file and exits Vim?
Answer: :wq
Explanation: The command :wq is used to write the changes made to the file and quit Vim.
- How can you navigate to the end of a line in Vim?
Answer: Use the $ key.
Explanation: Pressing the $ key will move the cursor to the end of the current line.
- How can you navigate to the beginning of a line in Vim?
Answer: Use the 0 (zero) key.
Explanation: Pressing the 0 key will move the cursor to the beginning of the current line.
- What is the purpose of the hjkl keys in Vim?
Answer: They are used for navigation.
Explanation: In Vim, the hjkl keys are used for efficient navigation. h moves the cursor to the left, j moves it down, k moves it up, and l moves it to the right.
- Which command is used to switch to insert mode in Vim?
Answer: Press i for insert mode.
Explanation: Pressing the i key allows you to start inserting text at the current cursor position.
- How can you delete an entire line in Vim?
Answer: Type dd.
Explanation: Typing dd allows you to delete the entire line at the current cursor position.
- What command is used to undo the most recent change in Vim?
Answer: Press u to undo.
Explanation: By pressing the u key in Vim, you can undo the most recent change made to the file.
- How can you repeat the previous command in Vim?
Answer: Type .
Explanation: The . (dot) command allows you to repeat the previous command executed in Vim.
- Which command can be used to search for a specific word in Vim?
Answer: Type / followed by the word to search.
Explanation: Typing / followed by the desired word and pressing Enter initiates a forward search for that word in Vim.
- How can you move the cursor to the beginning of the file in Vim?
Answer: Press gg.
Explanation: Pressing gg will move the cursor to the first line of the file.
- What command is used to open a new tab in Vim?
Answer: :tabnew
Explanation: The command :tabnew is used to open a new tab in Vim, allowing you to work on multiple files simultaneously.
- How can you copy a selected text in Vim?
Answer: Enter visual mode by pressing v or V, select the desired text, then press y to copy.
Explanation: In Vim, visual mode allows you to select a portion of text. Once selected, pressing y will copy the selected text.
- Which command can be used to replace all occurrences of a word in Vim?
Answer: :%s/old_word/new_word/g
Explanation: The command :%s/old_word/new_word/g is used to globally replace all occurrences of "old_word" with "new_word" in the current file.
- How can you move to the next occurrence of a searched word in Vim?
Answer: Press n.
Explanation: After performing a search in Vim using the / command, pressing n will move the cursor to the next occurrence of the searched word.
- What command is used to save the current file in Vim without quitting?
Answer: :w
Explanation: The command :w is used to save the changes made to the file without quitting Vim.
- How can you delete a word in Vim?
Answer: Press dw.
Explanation: Typing dw will delete the word from the cursor position.
- What is the purpose of the :q! command in Vim?
Answer: It is used to discard changes and force quit Vim.
Explanation: If you want to exit Vim without saving changes, you can use the command :q! to forcefully quit without any prompts.
- How can you undo all changes made in the current line and revert to the original version?
Answer: Type U in command mode.
Explanation: Pressing U in command mode will undo all changes made in the current line and restore it to the original version.
- Which command is used to redo an undone change in Vim?
Answer: Press Ctrl + r.
Explanation: After undoing a change, pressing Ctrl + r allows you to redo the change in Vim.
- How can you open multiple files in horizontal split windows in Vim?
Answer: Use the command :sp file_name.
Explanation: The command :sp file_name is used to open a new file named "file_name" in a horizontal split window in Vim, allowing you to work on multiple files simultaneously.