In the last post, I went over installation and some basic commands. Today we will learn about more advanced vim movements as well as the visual mode, we will also start configuring the text editor to match our needs. Let's start!
Visual mode is meant for the selection of text in your file. To enter visual mode press
v while in normal mode (remember, press
<esc> to enter normal mode from any mode).
This will activate the visual mode, the movements are the same as normal mode ie.
h j k l. You can move your cursor to select the text. To get out of the visual mode press
Now that you know how to select a piece of text, let's look at how you can copy and paste. Again let's activate the visual mode and select some text. Now to copy the selected piece of text press
y which in vim lingo stands for yank. The text is copied now move some lines down and press
p to paste the text, it will paste the text after your cursor.
To undo the last operation press
u . Needless to say, all these shortcuts work in normal mode.
We know how to move using the
h j k l keys but vim also provides other useful keybindings. Let's go over them one by one:-
e: Move to the end of a word.
w: Move forward to the beginning of a word.
W: Move forward a WORD (any non-whitespace characters).
b: Move backward to the beginning of a word.
$: Move to the end of the line.
0: Move to the beginning of the line.
You can even do something like
3b to move backward three words. As you can see this is extremely powerful and can improve your productivity many folds. You don't have to learn all these keybindings just start using them, and try to incorporate them in your daily work, soon they will become second nature.
As is the case is almost all the text editors, vim can also be configured. But the difference lies in the level of configuration vim allows. We can customize it the way we like it!
As we are using neovim we will be working with
init.vim which is called
.vimrc in vim world. Both these files do basically the same thing, they help us configure vim. All the configurations I'm going to do for neovim will be the same for vim.
.vimrc file is located in
$HOME/.vimrc if it isn't there create one. The typical location for
Let's create our config file first.
By default the
$HOME/.config/nvimdirectory will not exist. so let's create it first.
$ mkdir -p $HOME/.config/nvim
Now let's create our config file.
$ touch $HOME/.config/init.vim