Hopping Around NeoVim

1 minute read

I liked vim-easymotion in plain Vim. hop.nvim is the NeoVim equivalent. I had to script the keybindings (with which-keys so that they can be displayed as keybinding hints in the UI, too). The rendering of the “hop spots” is configurable and user-friendly by default. Hint-hopping is such a powerful way to move around in Vim.

LazyVim in NeoVide with Hop line hints LazyVim in NeoVide with Hop word hints LazyVim in NeoVide with Hop keybindings shown in which-key

(In Solarized dark this time)

I installed hop.nvim and registers its keybindings with LazyVim’s keybinding config and which-key for the group. In ~/.config/nvim/lua/plugins/hop.lua:

return {
  -- `hop` is an EasyMotion-like plugin allowing you to jump anywhere in a
  -- document with as few keystrokes as possible.
  {
    "smoka7/hop.nvim",
    version = "*",
    main = "hop",
    opts = {
      keys = "hklyuiopnm,qwertzxcvbasdgjf;",
    },
    keys = {
      { "<leader>hw", "<cmd>HopWord<cr>", mode = "", desc = "Hop to all words in the visible buffer; most useful!" },
      { "<leader>hl", "<cmd>HopLine<cr>", mode = "", desc = "Hop to the first column of each visible line" },
      {
        "<leader>hs",
        "<cmd>HopLineStart<cr>",
        mode = "",
        desc = "Hop to the first non-whitespace character of each line",
      },
      {
        "<leader>hv",
        "<cmd>HopVertical<cr>",
        mode = "",
        desc = "Hop to each line, keeping cursor column position the same",
      },
      { "<leader>h/", "<cmd>HopPattern<cr>", desc = "Validate search (`/`) with hints" },
      { "<leader>ha", "<cmd>HopAnywhere<cr>", mode = "", desc = "Hop anywhere" },
    },
  },

  -- Register the `<leader>h` prefix as with a group name in which-key.
  {
    "folke/which-key.nvim",
    opts = {
      defaults = {
        ["<leader>h"] = { name = "+hop" },
      },
    },
  },
}