DEV Community

Chig Beef
Chig Beef

Posted on

I Learned Neovim In A Weekend

Intro

I've tried a few times to start using Neovim because I know I will be fast at it. I try to use my mouse sparingly anyway, I can type fast (relatively), and code a lot, so it would make sense for me to make the jump. The problem is, I've tried. I currently use VScode, and I don't mind it, it gets what I want done, everything is right there waiting for me. Neovim hides a lot that's still there, but you access through keystrokes instead of by mouse.

Starting Up

Pre-transition, before my actual jump, there's a few things I started doing in VScode. Firstly, I would close the file tree when I wasn't using it. In default Neovim you don't see it when editing a file (some distributions show this, however), so I thought it would be a good idea to get used to that first.
Next, I started trying to use my mouse less. Even if it was a bit annoying, it already was starting to make me faster, and even just learning a tiny bit of these key commands helped me greatly. Here are some I used.

  1. Ctrl + Arrows, jumps entire words, this one was great
  2. Ctrl + Shift + Arrows, highlights entire words
  3. Home and End, I know that sounds stupid, but if you're not using them, learn to use them

Nothing too crazy right? But already, learning really easy combinations like this was saving me time.

Getting Into Neovim

First thing I did was get kickstart.nvim. I had heard it was extremely useful (and it was). It was very easy to install. I start reading through init.lua, and it told me to run :Tutor, which is almost 1,000 lines of learning how to use Neovim, to which I obviously ran that command and started reading. Obviously, it takes a bit of time to complete :Tutor, but it's well worth it. "hjkl" wasn't too hard to get used to, also repeating motions by using numbers was useful, such as using '5dd' to delete 5 lines. I highly suggest reading this file, especially since I didn't really know about the different modes, which is probably why I failed to switch the other times. You would start writing your code, then Neovim would say that it can't find that command, you would accidently type an i and then start typing, and so on, it was a nightmare. For those that don't know the modes, here is each mode and how to get between them.

  1. Insert mode, which in normal mode, press 'i'
  2. Normal mode, pretty much any time press 'escape'
  3. Command mode, from normal mode press ':'
  4. Replace mode, from normal mode press 'r'

Which all makes sense, but without knowledge of that, of course you would get stuck.

Throughout my readings I also tried to write simple programs, like some Go that printed out the first prime numbers under a million (which is the code I use to learn new languages).

init.lua

After finishing :Tutor, I started looking at init.lua, luckily, I already knew how to open the file tree, using :Ex. A helpful command in the file explorer (explorer mode?) is '-', which goes to the parent directory, which is way better than using 'k' until you're over ../ and pressing enter. Eventually, I found my way to init.lua, and started to read. More importantly, however, I was commenting and un-commenting things I didn't and did want. I would also mark things I still didn't understand, such as 'nerdfont', which I think has something to do with emojis (no clue), but I'll read up on it soon and decide whether to keep it or not. Most importantly, if it's not a priority to get me coding, then as long as it works, I'm good, I can learn it more in-depth a little later.

My Config

One of the first things I did was use relative numbering on the left side bar, like so.

vim.opt.relativenumber = true
Enter fullscreen mode Exit fullscreen mode

This is very useful for jumping around code and deleting code, while I don't really find myself using absolute line numbers that often.
Importantly, I was also making my own shortcuts, for example.

-- Easier way to Explorer
vim.keymap.set('n', '<leader>f', ':Ex<enter>')
Enter fullscreen mode Exit fullscreen mode

Although :Ex isn't too hard to type, having to press shift is too much work for something I'm going to be using a lot, especially before I figure out how to switch between files efficiently.
Also, the 'n' means that this command works in normal mode, 'f' means space and then f, my leader is set to space.
Something great about the kickstart config, is that it has this as an option.

-- TIP: Disable arrow keys in normal mode
vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
Enter fullscreen mode Exit fullscreen mode

Now I had to use "hjkl", which made learning Neovim easier.

Lazy

Lazy is the package manager that kickstart uses, and I think so far I'm finding that a good choice. There are a lot of packages that I have no clue what they do, but I'll keep kulling the ones I don't find necessary until I understand everything.

Telescope

Oh my gosh telescope is great, and just as I'm writing this I'm realizing I can use it to easily switch between my open files.

vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
Enter fullscreen mode Exit fullscreen mode

And all I have to do is press space twice! I think it's really important to read your config, you may not understand it the first time, but every time you go back to it, you'll learn something new (as I did just there).

Mason

Now, I know Mason is working, but I don't know exactly how. I know it's doing all my LSP stuff, and it's not erroring. I can install LSPs for any language I was (I currently have Lua, Python and Go installed). But getting that LSP working was extremely important for me to start coding, because it (and code coloring) is what makes you feel like you're not writing plain text. I also now had 'gopls', the LSP for Go (I already had it for VScode, but I just told Neovim it exists).

Auto-Formatters

This one is so important for Go. I knew I wouldn't be as effective in Go until 'gofmt' would run every time I saved. For those that don't know, 'gofmt' is like prettier but for Go, and is pretty much mandated.

Auto-Complete

I don't know much about this one, but I'm getting auto-complete suggestions, and I'm able to accept them. Currently I accept suggestions using 'ctrl+y', which I feel is a bit slow, so in future I'm going to change that to something faster.

Treesitter

This took most of the time to set up. The issue is I'm using Windows, and treesitter wasn't compiling parsers for my platform correctly, but this was actually an easy fix. All I had to do was install LLVM (and therefore clang) and use clang as the compiler instead. And it was all working!

Coding

Now I had auto-formatting, auto-complete, code coloring, and an LSP, I knew I was all set to start coding, and I'm pretty much just as fast as I was in VScode.
It's really not that hard to switch to Neovim, or maybe it is and I'm just really lucky. Either way, big thanks to Teej for Kickstart, it really helped (:
And my advice, even if you're not going to switch to Neovim, figure out how to do things faster, if you're coding so many lines maybe daily, or even weekly, you may as well do it right.

Top comments (0)