If you use Neovim right, then you feel like a god

Hey everyone!

For the last month and a half or so, I have been using Neovim. For the last month, I have exclusively used it when doing development, including modifying my Neovim configuration.

If you are unaware what Neovim is, it is a fork of Vim, but a lot of code in Vim has been refactored or redacted. The end result is a very fast modal text editor that allows for the use of fast and effective plugins. I have quite a few plugins added to my own configuration, although I don’t think I will be going over them in this post.

The first thing people might notice when using Neovim/Vim is either “how the hell do I get out of here?” or “why isn’t any text being written to the screen?” That is because when opening up a file, you are placed into Normal mode. Normal mode is used almost completely for navigating in the file or switching to another mode. You can do basic navigation with either with the arrow keys or with h, j, k or l. You might have noticed that I only mentioned keys. This is because with Neovim/Vim, you aren’t supposed to use your mouse at all, and in fact keep your fingers on the home row for fast typing as much as possible.

Typing “i” (or other commands) while in Normal mode will enter you into Insert mode. Insert mode works just as you would expect any text editor to work. When you type on the keys, those symbols appear at the location of your cursor.

There are apparently around a dozen different modes in Neovim/Vim, although so far I have really only used three or four of them. Visual mode (started by typing v while in Normal mode) which allows you to highlight text character by character the same as if you where to drag your cursor over it. The last one I have used is Visual Block mode, which is the same as Visual mode except you select text line by line. You can access Visual Block mode by typing V in Normal mode.

Aside from using the basic commands, you can also change any of the defaults to suit your liking. You can also come up with other, unique commands for your own workflows.

Neovim can feel overwhelming at first. I stated out just learning the h,j,k,l at first. Then I did VimTutor (open Neovim, and then in Normal mode type :Tutor. This will start a small series of lessons to teach you how to use Vim commands and movements).

I have done the VimTutor twice, the first time was in the middle of last year. I used the Neovim extension in VS Code for a long time to just get used to the basic movement and commands I have shared below. It was only recently that I watched some videos by ThePrimeagen and learned more commands and decided to fully immerse myself in it.

To get started I recommend you do the following:

  1. Do VimTutor at least once
  2. Look into using a Neovim Distro (basically an already set up version of Neovim with defaults). I did not do this because I wasn’t aware of them, but you should absolutely start here instead of making your own config. It takes too long to make a config to be worth it to a beginner because you don’t know how much it will speed you up.
  3. When you feel satisfied with VimTutor, take those commands and try to do some basic development. When you reach a situation where you feel like it is taking too long to do something, then try to see if there are commands that will better help you complete what you want to do.

Remember, the purpose of Neovim/Vim is that it should improve your speed of development. When you are first learning, you will go slower. But if you commit to really learn it then your speed should be faster than when using a traditional GUI integrated development environment. Of course, you can decide that the time to take to learn it is not worth it, or that you don’t like it. That is up to you.

4 Likes

Here are a list of Neovim/Vim commands I have used so far. Ones that are specific to plugins I have installed or are changes to the default I will note. Also, all commands only work in Normal mode unless I otherwise note it.

Basic Movement
h - move one character left
j - move one line down (I think "jump down" to help me remember this one")
k - move one line up ( I think "Kick the ball up" to help me)
l - move one character right

0 - go to the beginning of the line
_ or ^ - go to the first non-whitespace character in the line
$ - go the the end of the line
w - go to start of next word
b - go to start of previous word
e - go to end of next word
ge - go to end of the previous word
G - go to end of the file
gg - go to the beginning of the file
<number>G - go to line number <number>
} - jump to next paragraph 
     (Neovim/Vim considers something to be a paragraph if it is text with no empty lines)
{ - jump to previous paragraph
Ctrl+d - Jump down half a screen
Ctrl+u - Jump up half a screen

Basic Commands
dd - delete current line
d<command> - delete from cursor to whatever the command stipulates 
    (e.g. d$ would delete from cursor to end of line)
c<command> - delete from cursor to whatever the command stipulates, then enter insert mode 
    (e.g. c$ would delete from cursor to the end of line, then enter insert mode)
D - same as d$
C - same as c$

As I hinted above with d<command> and c<command>, many of these can be combined into the following format. If it is in [], it means it is not required

[number] [command] <movement>

So for example, 4j would have you move down four lines. 
4w would have you move to the start of word 4 words to the right. 
Similarly, 4dj would delete the next four lines, and 4dw would delete the next four words to the right. 
This can get complicated, but it is very useful.

Save/Quit
:w - Save current file
:q - Quit current file (will stop you if you have any changes)
:wq  Save and quite current file
:q! - Quit current file, removing all changes since last save

Change Mode
i - enter Insert mode before cursor
a - enter Insert mode after cursor
o - insert a line below current line, go to it, then enter Insert mode
O - insert a line above current line, go to it, then enter insert mode
I - go to first non-whitespace character and enter Insert mode
A - go to the last character and enter Insert mode same as 'a' command
v - Visual mode (select character by character with regular movement)
V - Visual Block mode (select line by line with regular movement)
Esc or Ctrl+C - Return to Normal Mode 
(slight modification by me with Ctrl+C, which works by default with most modes but not all of them)

Copy/Paste
y - (while in Visual or Visual Block mode) "yank" or copy
p - (while in Normal mode) paste

Undo/Redor
u - Undo
Ctrl+R - Redo

Special Horizontal Movement
f<char> - move forward on the line to <char>
F<char> - move backward on the line to <char>
t<char> - move forward up to <char> but not on it
T<char> - move backward up to <char> but not on it
     repeat movement:
         , - move in the opposite direction, but looking for the same <char>
         ; - move in the same direction as the previous command
di<char> - only works with characters that have pairs (like "", '', (), [], ect). 
        For example, di( would delete all text between ( and ) and then put your cursor between them
ci<char> - same as di<char> but you enter Insert mode at the end

Search
/<search_string> - forward search for <search_string>
?<search_string> - backwards search for <search_string>
   repeat movement:
     n - moving the same direction, go to next example of <search_string>
     N - moving in the opposite direction, go to previous example of <search_string>
* while on a word - forward search for that word
# while on a word - backward search for that word

Search and Replace
:%[start_line_num:end_line_num]/<search_string>/<replace_with>/[gci]
     This is the most complicated command I have used so far. instead of [start_line_num:end_line_num] you can replace with 's' which means "all lines in file". 
     So far, I have used it like this :%s/<search_string>/<replace_with>/g which searches for all occurrences of <search_string> in the file and replaces all of them with <replace_with>. 
     g means global, i means ignore case and c means 'confirm' so it will ask you for each replacement if you want to replace this example of <search>string>. i means ignore case.

Commands Specific to my Config that I use. Most of these are copied from ThePrimeagen, but I have started to modify.
<space>pv - go to current folder (so I can select a different file to edit)
<space>gs - "grep search" requires ripgrep. Type in the search string, then returns files that match that search string.
K -  Requires lsp-zero. Peek function definition
<space>gd - Requires lsp-zero. "go to definition" goes to the function definition
<space>vrn - Requires lsp-zero. "global rename" renames variable or function that the cursor is on globally
<space>vrr - Requires lsp-zero. "find reference" shows all references for the function or class the cursor is on
<space>git - Requires fugitive. Enters fugitives "git mode"
<space><space> - run :so (which sources the current file for the neovim config)

4 Likes

It looks like I could survive in Neovim with just the vi commands.
So the transition should be easy for an established vi user.
The advantage of plain vi is that it is available everywhere,
even in a recovery mode boot.

3 Likes

Well, Vim is essentially an extension of Vi, as it stands for “Vi Improved”. Neovim does change some things, but they aren’t changing the most basic stuff, they are changing the more complicated things and making them simpler/faster. I have only used Vi for maybe a few minutes, and at that time I hadn’t really learned to use Neovim/Vim. My guess is that you are correct, you could just start with what you already know.

1 Like

I have started with vim, because I need encryption and plain vi does not have that. I am not noticing any difficulties.

I think in some distros, if you enter vi you get vim anyway.
In others you get the originsl BSD vi.
It is possible to have both vi and vim installed simultaneously.
I have done that. They both work.

Termux, available in Android, uses vim.

3 Likes

Wrong! Have you tried the “busybox” in recovery mode on a Debian / Ubuntu system? They force you to use nano - there’s no vi… I hit this wall once and it was extremely frustrating… I guess I should try this in a more recent build of Debian, but I know busybox in Ubuntu 18 (the shell you get in rescue mode is “busybox”, busybox is kinda like command.com in MS-DOS).

Redhat based systems on the other hand - do have vi in their busybox when you’re in rescue / recovery mode…

And I wouldn’t know about Suse or Arch any others…

1 Like

I should have said " ought to be available everywhere"
What is wrong with those busybox people? It is not as if vi is a massive blob of code. They could include it easily.

i have struck a couple of other cases… cant remember where

3 Likes

Hi Jimmy,
Thanks for your thread.
I’m starting it in neovim, but installing it via LazyVim.
Apart from LSP, which plugins would you consider “essential” to install or to use?

Thanks for your help

Jorge

1 Like

@Tech_JA
I am using Packer because that is what The Primeagen used in his old video. I know Packer is both not the best and no longer actively maintained but it works for me. Eventually I will switch to lazy.nvim for package management.

Essential
fugitive.nvim - git integration

harpoon.nvim - allows you to add files to a buffer, then use commands to switch to different files. I use this one a lot.

telescope.nvim - fuzzy finder for Neovim

nvim-treesitter - improvements on Neovim’s tree-sitter, which primarily improves syntax highlighting.

Good to have
A good colorscheme - I currently use nightfox.nvim’s Carbonfox. But there are a lot of them that take advantage of treesitter.nvim

undotree - gives you a much longer list of undos you can have. For example, I’ve come back to code a week later and undid some stuff. Also a command that shows you the different states you can undo to. So you can kind of skip over changes you want to keep and only revert the things you want to. Not used it a ton yet however.

Fun to have
feline.nvim - a satusline plugin. This means that line at the bottom that shows the mode you are currently in, line number cursor is on, ect. If you do use this, you might need gitsigns.nvim and you might need a font with lots of logos. I copied the feline.nvim config from nightfox.nvim

Here is my Github link to my config.

Please note for the grep search command, you need to install ripgrep on your computer for it to work.

4 Likes

Hi
Jimmy,
Thanks so much for your reply and the description of each plugin you use and also for making your configuration available.
I’ll use them as a starting point because I’m a bit lost in the “neovim world”.
I didn’t have much time for the PC last week, but I’ll give you feedback as soon as I’ve tested them.

Once again, thank you
Jorge

1 Like

Jorge,
You are very welcome!

My advice to you is just use a “minimum” config for a bit. It is easy to get lost changing the configuration for Neovim instead of actually using it for developing. The plugins I provided in Essential and possible Good to Have would be what I would consider for a minimum config.

As you go along, you will see some stuff you want to try or find some problems you want to solve. At that time, change or add to your config. For example, I copied all the remaps from ThePrimeagen, but he uses a Dvorak keyboard, whereas I use QWERTY. As I started to use more and more of these remaps, I realized some of them weren’t ideal, so I changed them.

I think its good you started with lazyvim. If I knew about Neovim distros before I got started, I would have started with one of them.

It looks like LazyVim already comes with a colorscheme that works with treesitter.nvim. Looking at it, they provide a way to set up these plugins very easily. See here: Core Plugins | LazyVim

And here for some extras: Extras | LazyVim

I see at least harpoon, telescope.nvim and nvim-treesitter. They don’t see to have fugitive.nvim, but instead have gitsigns.nvim. I technically have this plugin, but only so I can see git stuff on my statusline. It seems like people like it though. I do not see undotree. It already comes with a good colorscheme that takes advantage of nvim-treesitter, so no need to change it.

1 Like

Hi Jimmy,
Thank you for your advice.
I’ll follow what you’ve said, because it’ll be easy for me.

I’ve been following the neovim subreddit, but I’m really lost, but I don’t want to give up and stay on VSCodium, which is the easiest solution

I’ll see if I can do more tests with neovim today and I’ll give you feedback as soon as I do…

Once again, thanks for much for your help
Jorge

1 Like

@Tech_JA
Have you done the Neovim Tutor? Open Neovim and then type :Tutor. This is only relevant if you are not used to the Vim movement yet.

I felt lost when I started too. I honestly took a few weeks to just do the basic movement (e.g. h, j, k, l for the arrows, w/e for words, ect). I got busy with stuff, so I did it off and on, but after you feel somewhat comfortable with the basic movement then you should dive in.

I dived in by doing a simple programming challenge from Coding Challenges - Intro | Coding Challenges

I also learned a new programming language at the same time, but that is not necessary. The point is to make a complete program while using Neovim. When you find yourself doing something that seems not ideal (say you need to move down several hundred lines to modify a function) then see if you can think of a better way to do it. If not, then try to research on the internet. For that particular scenario, you could either search with / or you could jump down a half screen with Ctrl+d. The search is better, but both are better than just pressing j a few hundred times.

1 Like