Azure and DevOops

Basics of Vim/Neovim continued

ยท Christian Piet

Basics of Vim/Neovim continued

In my previous post (https://manbearpiet.com/posts/nvim/), I mentioned several modes and basics of editing in Vim/Neovim. In this post, I’ll continue the topic and show you how to use Tutor and help, as well as what you can do with Visual mode.

Help and Tutor

In the last post, I mentioned how to access and quit help articles in Vim/Neovim; these articles contain gems. There is even a tutoring tutorial program you can access with the Commandline Mode command using :Tutor. This program will guide you through the Neovim tutorial and will contain help with links.

Select all text on line

The default Tutor is :Tutor tutor, but there are also :Tutor vim-01-beginner and :Tutor vim-02-beginner. I couldn’t access Tutor because I copied and pasted some flawed configuration code, d’oh! But make sure to check :Tutor, it’s excellent. If the area of the help is too small, you can drag the borders with ehh your mouse.

Help can be accessed with the :help, or :h-command. This also supports tab-completion, and you can cycle through the articles with tab/shift-tab.

Select all text on line

Visual Mode

Visual mode is a mode in which you select text relative to your cursor’s position. If you’re still using your mouse, although it doesn’t exist, dragging across a sentence, double-clicking, and dragging across lines is what Visual mode is. It’s a swift way to select a lot of text and allows you to use your operators. Visual mode grants you flexibility in selecting the text.

Visual mode comes in three flavors:

v

v, starts visual mode with just the character under your cursor selected, and with the motion keys (e.g. hjkl), you can choose more text. Navigating with your cursor in the v mode will select all text between your visual starting position and your cursor’s position. So if your cursor goes up with k in the middle of a sentence, it will select all text on the line backwards up to the position of the cursor.

As an example if you want to visually select all text from your cursor up to the end of the line, you can do v$, which enters visual mode at your cursor position. Say you’d want to yank/copy the selected text, you could press y' to do so, delete it with d’ or change it.

This can be handy if you want to copy all text except the line ending. Of course, you can also press Y/D/C to do the same, but this will also include the line ending. v is excellent to use if you need precision.

Select all text on line

Ctrl-v

Ctrl-v or blockwise Visual mode is a bit odd in the sense that it starts at the cursor’s current position, but moving the cursor will select only the character relative to the cursor’s starting position. So if you go up/down a line, it doesn’t select all text on the line between your starting position and your cursor’s position, like v does.

The way I remember this is it feels a lot like selecting a column in a spreadsheet, then you’re also not interested in the rows before, just in the cells above or under your starting position. Ctrl-v is excellent when you need extreme precision or when you want to edit leading characters. Try it with gg (start of the file), Ctrl-v, GG (end of file), and d to delete the selected position.

One handy trick I frequently use in other IDEs is the multi-line insert; you can also do this with Ctrl-v. Select the positions you’d want to enter text in, press Shift+i, make your change on a single line, and press Esc.

Select all text on line

V

V starts visual mode on the line your cursor is positioned at and selects all the text on that line. When you go up or down, it includes all text on that line and all text and other selected lines. This is the mode I use the most, as it allows me to select whole lines quickly.

Select all text on line

Fin

I don’t frequently use visual mode, but some people like it, so it can be handy to have it in your toolbelt and know how to use it. The help for visual mode is excellent and can be found at :h visual-mode. I hope this was helpful. Happy coding, everyone!

PS: There are some excellent resources I found on the web, be sure to checkout:

#neovim #vim #basics