Neovim vs Vim

Neovim is a fork of Vim which is more extensible than Vim and has built in LSP(Language Server Protocol) support. Neovim started using Lua in their recent version while Vim is still using viml (which is made particularly for vim to enhance its funcitonality)

For most users Neovim is a better choice


Getting started with Neovim

Open a file using Neovim

nvim myfile.txt

  • opens the file myfile.txt in Neovim text editor

Pre-requisites

Before proceeding, we should understand some terminologies:

Normal Mode: This is the mode that Neovim open in by default.

In normal mode you can’t insert, type in the document. Here you’ll use keys for navigation, selecting things, copying text, pasting text and many more

Insert Mode: In insert mode you can type things in the file like normal text editors

Visual Mode: This is used for selecting text (We’ll talk about this later)

Command Mode: Here you type your commands

For now just remember about Normal and Insert mode.

Inserting in file

When you’re in normal mode you press i to go into insert mode

Once in insert mode you can type the way you normally type in any other Text Editor

To Exit the insert mode press Esc key
Now you’re in Normal Mode again

When i opened Vim for the first time i was lost like: where the hell is this exit button LOL

Exiting Neovim

While you’re in normal mode

:q

will exit you out of Neovim.

Note: if you have made some changes to the document and wanted to exit using :q it won’t let you

So you have two options :

:q!

Force exit Neovim without saving what you’ve done

:wq

Save and then exit


When you open a file using Neovim you’re in the Normal mode.

Here you’ll use keys for navigation in the file instead of typing things

j -> move one line down $\downarrow$

k -> move one line up $\uparrow$

l -> move one letter to the right $\rightarrow$

h -> move one letter to the left $\leftarrow$

Jump from word to word

Jump in forward direction: In normal mode press w to jump to the word which is next to where your cursor is

Jump in backword direction: In normal mode press b to jump to the word which is previous to where your cursor is

Note: From now on, I won’t be telling you to be in normal mode to do these things

Jump to start or end of line

^ - Jump to the start of the line. ( This isn’t Ctrl it’s Shift+6 )

$ - Jump to the end of line ( Shift + 4)


Insert and Append

Although i’ve talked about how to insert above . But since you have block type cursor in normal mode then you don’t whether it’s going to insert before the cursor block or after the cursor block.

Suppose you cursor block is on l in the word file , then:

i -> start insert mode before l i.e. b/w i and l

a -> start insert mode after l i.e. b/w l and e

Insert at the start or End of line

I -> go to the start of the line and enter into insert mode

A -> go to the end of the line and enter into insert mode


Undo and Redo

u : undo whatever you have done in the last instances

Press u again and again if you to want to undo more and more

Ctrl + r : redo whatever you have undid in the last undo


Search for word in document

When you are in Normal Mode press / to search for an word

/himanshu

will highlight all instances of himanshu in the document

Press Enter if you think the highlighted word is what you’re looking for

Press n to jump from one instance of himanshu to other in forward direction

Press N to jump from one instance of himanshu to other in backword direction