Texts | Christofer Sandin

01001100 00101101

Terminal: Exploring Vim after 20 years of writing code

As a middle-aged CEO and developer, I’ve found myself increasingly occupied with running the company and maintaining a general project overview lately. I needed something new to explore. Therefore, after more than 20 years of coding in regular text editors and IDEs, I decided to explore Vim.

Why? There was no particular reason; I was just a little curious and needed a challenge. I did like the idea that you spend more time editing than writing, so there should be a specific mode for that.

This text is not a general introduction to Vim - there are many available on the Internet - but I have written down a few notes from that endeavor.


The whole thing did not start with Vim. At first, I took a look at Helix. Helix is an editor that functions similarly to Vim and Neovim. It’s fast, written in Rust, and requires almost zero configuration. I liked it a lot and spent some time in it. It took a bit of getting used to working in different modes, but I could see the appeal.

Helix is still a very niche product, and after reading and reviewing tutorials, I switched to Neovim mainly because of the extensive amount of material and plugins available. Neovim is an extension of Vim, so learning this provides a solid foundation for Vim motions as well. I also liked learning Lua, the programming language used to configure Neovim.

Many people suggest starting nvim, pressing the <ESC> key, typing :Tutor, and then <ENTER> if you need help with the basics.

Another great place to start is to go all-in on the kickstart.nvim project. You can also read the project’s config file, which is full of comments and ideas, directly on GitHub and pick and choose the things you like.

Both approaches are good options and might suit you, but I needed to see what was doable, so I started watching some "set up Neovim from scratch" videos on YouTube to get into it.

Have I switched to Neovim exclusively? No, I have not. Have I gained insights into what’s out there? Yes, I have. Currently, I’m in the middle, but I can see myself using an editor with Vim key bindings soon.


Key bindings

The most interesting aspect of Vim and Vim-based editors is learning how to work in different modes.

Normal mode

You start in normal mode, which is your base, and all interactions begin here. Move around files and select what to edit.

Navigation

Editing text

Edit

Folding code

Quit vim

Auto-complete

Selection

Files and buffers

An open file lives in a buffer. You can display multiple buffers at the same time, and you can have the same file open in many buffers.

Buffers

Splits

Macros

Record interactions and reuse them with macros.

Recordings

  1. Record: q a (keystrokes) q
  2. Play: @ a
  3. Play multiple (15) times: 15@a

Visual mode

Working in visual mode allows you to select text and view a visual representation of what you have selected.

Select a paragraph

Select block

Select until next instance

Select Word

Copy a word and replace another word


Insert mode


Third-party plugins

Before committing to third-party plugins and extensions, it is wise to explore the basic commands in your applications. It is also always a good idea to keep dependencies to a minimum.

That said, there are a few plugins that significantly enhance the user experience in Neovim, and if they have a good reputation and solid support, I’m not opposed to using them.

The foundation

From what I gathered during my research, it appears that lazy.nvim is a reliable way to manage plugins.

Here is a list of the ones who function as a foundation for my setup:

The following ones are outstanding:

telescope.nvim

Telescope is an extendable fuzzy finder over lists for Neovim. It is "built on the latest awesome features from Neovim core," which I guess must be good. It is centered around modularity, allowing for easy customization.

vim.keymap.set("n", "<leader><leader>", builtin.oldfiles, {})
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})
vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
vim.keymap.set("n", "<leader>fr", builtin.registers, {})

oil.nvim

If you like to step away from the file tree view on the left-hand side of the code and use a more native-feeling solution, you want to try oil.nvim.

Hitting the - key displays a list of the current directory, and you can use your Vim skills to add, delete, and rename files.

Using g will display other options if you have Which Key installed.

Currently, this is my preferred method for quickly and easily performing file-related tasks within Neovim.

nvim-surround

Surround text with a character or a tag.

ysiw) – add "(" and ")" around word
ys$t - adds a tag around the text from the cursor position to the end of the line

ds" - delete " around text
dst - delete tag around text

cs'" - change quotes from ' to "

// Comment.nvim

Comment your code in style.

Putting a smile on your face

These are the others I use at the moment;


Links

References and videos

Official links to repo and plugins

Themes