Vim is a powerful text editor accessed through the terminal. It can be a little challenging to figure out at first, so here is a small guide to make getting used to it a little bit easier!
First, you should know how to open and close Vim. Here is a guide on how to do it properly:
One of the first commands you need to learn in Vim is how to add text. There are two ways of inserting text in Vim, i or a. While these two may seem the same, the key difference is that i inserts text just before your cursor, while a lets you write anywhere on your page with more ease, starting by moving your cursor one space forward.
The next thing you need to learn to be successful using Vim is how to delete text. There are a few ways of doing this, so I've broken them down here:
At this point you've probably been practicing with Vim and have likely made a mistake. This can be really annoying, but don't worry, there is a way to fix it. Just press u to undo your last change. If you want to undo all the changes made on a line, press U. If you've undone something you didn't want to, you might have found that using u doesn't fix it. To redo a change, press Ctrl + R.
You can also use vim to write html code. For example, here's how a minimal html page created using vim might look:
<!DOCTYPE html> <html lang="en"> <head> <title>Hello World</title> </head> <body> <p>This is my website!</p> </body> </html>
Now you know the basics of Vim and what it can hep you do. This guide is a great starting point, but if you want to go deeper and learn how to navigate and use Vim with greater ease, type vimtutor into the terminal or look up vim commands in your browser.
| Use | ||
|---|---|---|
| Navigation | w | Jumps forward to the start of a word |
| b | Jumps backwards to the start of a word | |
| 0 | Jumps to the start of the line | |
| $ | Jumps to the end of the line | |
| gg | Goes to the first line of the document | |
| G | Goes to the last line of the document | |
| nG | Goes to line n | |
| % | Used to move to the matching character: (), {}, [] | |
| Editing | r | Replaces a single character |
| R | Replaces more than one character, until ESC is pressed | |
| . | Repeats the last command used | |
| Insert Mode | I | Insert at the beginning of a line |
| A | Append text at the end of the line | |
| o | Open a new line below the current line and append | |
| O | Open a new line above the current line and append | |
| Visual Mode | v | Enters visual mode |
| y | Copy(yank) marked text | |
| p | Paste text after your cursor | |
| u | Replaces text with lowercase | |
| U | Replaces text with uppercase | |
| File Navigation | :w | Saves(writes) edits to the file |
| :q | Exits the file | |
| :e | Switches to a new file | |
| :vsp | Opens a new file alongside your current one | |
| Ctrl w | Switches between files opened with :vsp | |
| Ctrl h | Switches between files opened with :vsp | |