Vim is an amazingly powerful, yet super simple text editor. It's an easy to use and free text/programming editor that anyone can use regardless of their skill level.
You can use vim both in the terminal and in a GUI version (gvim). You can also use it over a remote network session (ssh).
Here are some Vim tips and tricks that will help you get started with Vim.
Basic Navigation
To move around, we use the h, j, k and l keys to move left, down, up, and right respectively.
- h moves the cursor one character to the left.
- j moves the cursor one line down.
- k moves the cursor one line up.
- l moves the cursor one character to the right.
Vim also uses the arrow keys to move around too!
- gg moves to the top of the file.
- G moves to the bottom of the file.
Opening and saving
In order to save a file with vim, you need to first open it with vim editor. You can do so with the command line:
vim filename.txt
vim /home/you/Documents/filename.txt
To save the file, press ESC
followed by :w!
Inside vim you can open files using ESC
followed by :e filename
.
Quit vim
To quit vim, you can either press ESC
followed by :q!
(quit without saving) or press ZQ
.
To save and exit, press ESC
followed by :wq!
.vimrc
While vim does a lot of things out of the box, you may want to configure it to work with certain programming languages, to show line numbers etc.
You can customize with your .vimrc
file. You can configure vim with that file.
To enable syntax highlighting:
" Turn syntax highlighting on.
syntax on
To enable line numbers
" numbers on each line
set number
If you don't want to configure manually, you can generate a vimrc config file on this website.
Programming in vim
You can use vim as a programming IDE. I do this quite a lot, as vim is a very powerful editor and great for editing some files on the fly.
Let's say you want to create a hello world program. The first thing you will want to do when opening vim
$ vim
Run the following command:
:edit hello_world.py
This will open up a blank python file. From here, you can start writing code by pressing i (or insert) to go into insert mode.
Write your code.
After press esc
to exit insert mode, the buffer should be saved automatically. You can then run esc :wq to close and save the file.
what's next? 😄
It can take a while to get used to all the keyboard commands when learning vim. It can be challenging to use vim while at the same time learning vim.
So what to do? If you want to learn vim quickly, you can use vim.is
Top comments (0)