backdround/improved-ft.nvim

github github
motion
stars 40
issues 1
subscribers 3
forks 2
CREATED

2023-11-20

UPDATED

11 months ago


Improved-ft.nvim

It's a feature-rich, but straight-forward Neovim plugin that improves default f/t hop abilities.

Additional features:

  • Works in multiline;
  • Works in insert mode;
  • Has the additional post offset;
  • Has the ability of stable next / previous hops (don't depend on last hop direction).

Preview

Basic

Past a character

In insert mode


Basic configuration

local ft = require("improved-ft")
ft.setup({
  -- Maps default f/F/t/T/;/, keys.
  -- default: false
  use_default_mappings = true,

  -- Ignores case of the given characters.
  -- default: false
  ignore_char_case = true,

  -- Takes a last hop direction into account during repetition hops
  -- default: false
  use_relative_repetition = true,

  -- Uses direction-relative offsets during repetition hops.
  -- default: false
  use_relative_repetition_offsets = true,
})

Advanced configuration

local map = function(key, fn, description)
  vim.keymap.set({ "n", "x", "o" }, key, fn, {
    desc = description,
    expr = true,
  })
end

map("f", ft.hop_forward_to_char, "Hop forward to a given char")
map("F", ft.hop_backward_to_char, "Hop backward to a given char")

map("t", ft.hop_forward_to_pre_char, "Hop forward before a given char")
map("T", ft.hop_backward_to_pre_char, "Hop backward before a given char")

map(";", ft.repeat_forward, "Repeat hop forward to a last given char")
map(",", ft.repeat_backward, "Repeat hop backward to a last given char")
local map = function(key, fn, description)
  vim.keymap.set({ "n", "x", "o" }, key, fn, {
    desc = description,
    expr = true,
  })
end

map("s", ft.hop_forward_to_post_char, "Hop forward after a given char")
map("S", ft.hop_backward_to_post_char, "Hop backward after a given char")
local imap = function(key, fn, description)
  vim.keymap.set("i", key, fn, {
    desc = description,
    expr = true,
  })
end

imap("<M-f>", ft.hop_forward_to_char, "Hop forward to a given char")
imap("<M-F>", ft.hop_backward_to_char, "Hop forward to a given char")

imap("<M-t>", ft.hop_forward_to_pre_char, "Hop forward before a given char")
imap("<M-T>", ft.hop_backward_to_pre_char, "Hop forward before a given char")

imap("<M-;>", ft.repeat_forward, "Repeat hop forward to a last given char")
imap("<M-,>", ft.repeat_backward, "Repeat hop backward to a last given char")