How to exit vim and other important key bindings!
vim is almost everywhere available text editor, lack of mouse and GUI can scare new users, but don't worry you don't need to learn…
vim is almost everywhere available text editor, lack of mouse and GUI can scare new users, but don't worry you don't need to learn everything to use vim, you need only a few key bindings to start being productive with vim, lets start
What is command mode
Command mode in vim is a mode where the user can enter commands that perform file-level operations, like writing to a file or entering commands that allow the user to copy, cut, and paste text.
What is the input mode
Input mode is the mode where the user can type text into the file.
- ESC: Switch from input mode to command mode.
- i: Switches from command mode to input mode where the cursor is.
- o: Opens a new line below the current cursor and goes to input mode.
- :wq write to file and exit.
- :q! Quits without writing to file.
- w filename : Writes the current file with a new filename.
- dd: deletes the current line.
- yy: copies the current line.
- P: Pastes the current selection
- v: Enters visual mode, allowing you to select a block of text using arrow keys. Use d to cut, or y to copy the selection.
- u: undo the last command, repeat as needed.
- ctrl+r: redoes the last undo.
- gg: Goes the to first line in the document.
- G: Goes to the last line in the document.
- /string : Searches for a string from the current position forward.
- ?string : Searches for a string from the current position backward.
- ^ : Goes to the first character of the current line.
- $ : Goes to the last position of the current line.
- !ls : Adds the output of ls (or any other command) in the current file.
- %s/old/new/g : Replaces ALL occurrences of old with new.
- %s/old/new/ : Replaces First occurrence of old with new.
I hope you enjoyed this super short article! i tried not to write a lot of text but only to mention the most used commands and a brief explanation, vim is a text editor, you don't need to know all the features to be productive with vim.