loading...
Cover image for Let's learn Vim - Moving and The Configuration File

Let's learn Vim - Moving and The Configuration File

thetinygoat profile image Sachin Saini ・2 min read

Let's Learn Vim (4 Part Series)

1) Let's learn Vim - The Basics 2) Let's learn Vim - Moving and The Configuration File 3) Let's learn Vim - Basic Configuration 4) Let's learn Vim - Plugins

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!

The visual mode

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 <esc> .

Copy and paste and undo

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.

Moving even faster

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.

The vim configuration file

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.

The .vimrc file is located in $HOME/.vimrc if it isn't there create one. The typical location for init.vim is $HOME/.config/nvim/init.vim.

Let's create our config file first.

  • By default the $HOME/.config/nvim directory 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

And there you go, we have our config file. In the next part, we will start customizing our neovim installation. See you soon!
Follow me on Github and Twitter

Let's Learn Vim (4 Part Series)

1) Let's learn Vim - The Basics 2) Let's learn Vim - Moving and The Configuration File 3) Let's learn Vim - Basic Configuration 4) Let's learn Vim - Plugins

Posted on by:

thetinygoat profile

Sachin Saini

@thetinygoat

Currently a student, love to post about all things tech.

Discussion

markdown guide
 

I think it would be better to make the distinction between neovim and vim in the title of the posts.

 

They both are practically the same and I provide instructions for both, is there any specific reason you want the distinction to be made ?

 
[deleted]
 
 

I saw it on LinkedIn, pay attention to the social media presence it's really powerful, you never know who's looking at your profile

Oh, wow! thanks a lot, i'll fix it :)

 

neovim + vim plug = vim on steroids

 

Check out the vim adventures here: vim-adventures.com/ super cool website which helps us learn vim with a game