Table of contents
During this article, I want to discuss the rules I'm trying to follow to be even more productive in Vim or Neovim. Many times, when people start using Vim, they might pick up bad habits. Similarly to other habits, getting rid of them isn't easy. On the other hand, beginning to work in Vim is hard, and if we put good practices on top of that, it will make things impossible to lift. So it looks as if there were no other choices than simply doing what you do and, with time, correcting the places that need improvements. I found a couple of places that could be improved, and today, I decided to share my research results with you. So, without further ado, let's jump right in.
Above all, it's worth reminding you that the fewer keys you use to achieve the expected results, the better for you.
Tip 1: Use less j , k , l , and h
Vertical navigation and actions
Try to avoid using
3k - Navigate 3 lines above3- - Navigate 3 lines above to the beginning of the line3j - Navigate 3 lines below3+ - Navigate 3 lines below to the beginning of the line3dj - Remove 3 lines bellow3ck - Change 3 lines aboveCtrl+u - Scroll half a screen up without moving the cursor position.Ctrl+d - Scroll half a screen down without moving the cursor position.G - Go to the last line of the file.gg - Go to the first line of the file.H - Move the cursor to the top line visible in the current window.M - Move the cursor to the middle line visible in the current window.L - Move the cursor to the bottom line visible in the current window.} - Move the cursor to the beginning of the next paragraph.{ - Move the cursor to the beginning of the previous paragraph.) - Move the cursor to the beginning of the next sentence.( - Move the cursor to the beginning of the previous sentence.% - Move the cursor to the matching parenthesis, square bracket, or curly brace.# - Search for the word under the cursor backward in the document.* - Search for the word under the cursor forward in the document./ - Initiate a forward search in the document.? - Initiate a backward search in the document.
Horizontal navigation and actions
With these keys, you can navigate or do some action faster vertically, and here are the keys to help you navigate and modify the text with fewer keys horizontally:
^ - Move the cursor to the beginning of the current line.$ - Move the cursor to the end of the current line.f - Find the next occurrence of a character on the current line.F - Find the previous occurrence of a character on the current line.t - Move the cursor just before the next occurrence of a character on the current line.T - Move the cursor just after the previous occurrence of a character on the current line.dta - Delete from the cursor position up to and including the next occurrence of the character 'a'.dTa - Delete from the cursor position up to but not including the previous occurrence of the character 'a'.cfi - Change from the cursor position to just before the next occurrence of the character 'i'.cFi - Change from the cursor position to just after the previous occurrence of the character 'i'.w - Move the cursor forward to the beginning of the next word.b - Move the cursor backward to the beginning of the previous word.e - Move the cursor to the end of the current word.W - Move the cursor forward to the beginning of the next WORD.B - Move the cursor backward to the beginning of the previous WORD.E - Move the cursor to the end of the current WORD.A - Move the cursor to the end of the current line and switch to insert mode.I - Move the cursor to the beginning of the current line and switch to insert mode.S - Delete the entire line and switch to insert mode.D - Delete from the cursor position to the end of the line.
Tip 2: Use motion plugins
There are lots of plugins that help you to navigate with fewer keys. Here are a few of them:
- leap.nvim
- flit.nvim
- clever-f.vim
- vim-easymotion
- vim-smalls
- vim-sneak
- lightspeed.nvim
- hop.nvim
- flash.nvim
And there are many more.
Personally, I used
And there are good reasons why I chose
In addition to
My configurations are pretty simple:
leap.lua:
return {
'ggandor/leap.nvim',
dependencies = {
"tpope/vim-repeat"
},
config = function()
vim.keymap.set('n', 's', function ()
local focusable_windows = vim.tbl_filter(
function (win) return vim.api.nvim_win_get_config(win).focusable end,
vim.api.nvim_tabpage_list_wins(0)
)
require('leap').leap { target_windows = focusable_windows }
end)
end,
lazy = false,
}
flit.lua:
return {
'ggandor/flit.nvim',
config = function()
require('flit').setup {
keys = { f = 'f', F = 'F', t = 't', T = 'T' },
-- A string like "nv", "nvo", "o", etc.
labeled_modes = "nvo",
multiline = false,
opts = {}
}
end
}
To cover
- Leap
- Flit
- Hardtime
- UltiSnip