TL;DR
Use hop.nvim for leap.nvim-like bidirectional jumps but only for the current line.

Introduction

The search is finally over. I can have leap.nvim-like jump for the current line. Little did I know, hop.nvim is the plugin that does exactly what I want.

Features

  1. Bidirectional jump. It means that regardless of the cursor location, I can jump to anywhere in the current line (leap.nvim default). I no longer need to remember to use f to jump forward and F to jump backwards.
  2. 2-character. The labels appear only after 2-character search (same as leap.nvim)

My hop.nvim Configuration

return {
  "smoka7/hop.nvim",
  event = "VeryLazy",
  opts = {
    keys = "jklasdfghqwertyuiopzxcvbnm",
    create_hl_autocmd = false,
    dim_unmatched = false,
    teasing = false,
  },

  config = function(_, opts)
    vim.api.nvim_set_hl(0, "HopNextKey", { fg = "#000000", bg = "#CCFF88", bold = true })
    local hop = require("hop")

    local keymap = {
      ["f"] = function() hop.hint_char2({ current_line_only = true, jump_on_sole_occurrence = false, }) end,
      ["t"] = function() hop.hint_char2({ current_line_only = true, jump_on_sole_occurrence = false, hint_offset = -1, }) end,
    }

    local modes = { "n", "x", "o" }
    for key, func in pairs(keymap) do
      vim.keymap.set(modes, key, func, { remap = true })
    end
    hop.setup(opts)
  end,
}

With the field keys, I can almost guarantee that I can reach wherever I want in the current line with f{2-char}j.

Q&As

What don’t you just use leap.nvim while jumping in the current line?

I don’t like the visual clutter. When my intention is to jump somewhere in the current line, I don’t want labels to appear outside of the current line.

As outlined in my previous blog post, find-extender.nvim was my previous good-enough solution; but the author abandoned the plugin and it never felt complete: the bidirectional jump only works for normal mode (i.e., other modes don’t work) and it was kind of buggy. hop.nvim, on the other hand, is much more reliable and feature complete.