Hop (Navigation for Neovim)
3 min readFeb 7, 2023
Neovim motions on Speed
Hop is an EasyMotion-like plugin allowing you to jump anywhere in a document with as few keystrokes as possible. It does so by annotating text in your buffer with hints, short string sequences for which each character represents a key to type to jump to the annotated text. Most of the time, those sequences lengths will be between 1 to 3 characters, making every jump target in your document reachable in a few keystrokes.
Requirements
- Neovim ≥ 0.5
Installation
- Insertion of github repository should be done in plugins.lua file so that Hop gets installed in our IDE.
-- Plugins.lua
return {
-- Bufferline
{
'akinsho/bufferline.nvim',
dependencies = 'nvim-tree/nvim-web-devicons'
},
-- Colorscheme
{
'folke/tokyonight.nvim',
},
-- Hop (Better Navigation)
{
"phaazon/hop.nvim",
lazy = true,
},
-- Lualine
{
'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' }
},
-- Which-key
{
'folke/which-key.nvim',
lazy = true,
},
}
- The lazy keyword enables lazy-loading of Hop plugin. This will only load Hop when you want to search inside the editor.
- Save the file using
Space + w
and Invoke Lazy withSpace + p
to check the status of extension.
- Install the plugin with
Shift + i
and configure Hop.
Configuration
- Create a new file hop-config.lua in your lua directory.
- Add Keybinding to use hop when required. This is a minimalist configuration which I use, A better configuration than this can be implemented by diving deep into its documentation provided in thier github repository.
require'hop'.setup { keys = 'etovxqpdygfblzhckisuran', term_seq_bias = 0.5 }
-- Changing the default f keyword
vim.api.nvim_set_keymap('', 'f', "<cmd>lua require'hop'.hint_char1()<cr>", {})
-- Pattern Matching with t keyword
vim.api.nvim_set_keymap('n', 't', "<cmd>HopPattern<CR>", {noremap = true})
Source Hop to Main Config
- Include hop-config.lua file in init.lua using
require
keyword.
require "keymaps"
require "options"
require "hop-config" -- Added this line to initial file
require "lazy-config"
require "lualine-config"
require "bufferline-config"
require "whichkey"
- Restart Neovim and Navigate anywhere through “f” keyword.
- Open any file -> Type ‘f’ to search any alphabet -> Hop enables navigations -> Navigate through the suggestions.
Hop Alternatives
Neovim From Scratch
- If you want a complete installation and configuration of Neovim from Scratch, then you can head over to my NEOVIM SERIES.
- This series is updated regularly, with updates and inclusion of newer plugins which improves the wholesome IDE experience of Neovim.