Skip to content

chrisbellboy/improved-ft.nvim

 
 

Repository files navigation

Improved-ft.nvim

It's a Neovim plugin that improves default f/t jump abilities

It provides:

  • multiline jump to a given character.
  • ability to jump to a user defined vim-pattern.
  • stable next / previous jumps that don't depend on last jump direction.
  • additional post character offset (as well as default pre and none offsets).

Differences to other similar plugins:

  • Doesn't use any labels.
  • Doesn't depend on vim-repeat.
  • Uses lua only.
  • Adds ability to jump to a user defined vim-pattern.

Preview

Jump to a character (pre / none / post)

Jump inside / outside round brackets

Jump to a number


Configuration example

local ft = require("improved-ft")
ft.setup({
  -- Maps default f/F/t/T/;/, keys
  -- default: false
  use_default_mappings = true
  -- Ignores case of interactively given characters.
  -- default: false
  ignore_user_char_case = true
})

Additional configuration examples

Jump pass a character
-- Jump forward pass a given by user character.
vim.keymap.set({"n", "x", "o"}, "s", function()
  ft.jump({
    direction = "forward"
    offset = "post",
    pattern = nil,
  })
end)

-- Jump backward pass a given by user character.
vim.keymap.set({"n", "x", "o"}, "S", function()
  ft.jump({
    direction = "backward",
    offset = "post",
    pattern = nil,
  })
end)
Jump pass any quotes
-- Jump forward pass any quotes.
vim.keymap.set({"n", "x", "o"}, "s", function()
  ft.jump({
    direction = "forward"
    offset = "post",
    pattern = "\\v[\"'`]",
  })
end)

-- Jump backward pass any quotes.
vim.keymap.set({"n", "x", "o"}, "S", function()
  ft.jump({
    direction = "backward",
    offset = "post",
    pattern = "\\v[\"'`]",
  })
end)
Jump inside round brackets
-- Jump forward inside round brackets.
vim.keymap.set({"n", "x", "o"}, "s", function()
  ft.jump({
    direction = "forward"
    offset = "post",
    pattern = "\\M(",
  })
end)

-- Jump backward inside round brackets.
vim.keymap.set({"n", "x", "o"}, "S", function()
  ft.jump({
    direction = "backward",
    offset = "post",
    pattern = "\\M)",
  })
end)
Jump inside / outside round brackets
-- Jump forward inside / outside round brackets.
vim.keymap.set({"n", "x", "o"}, "s", function()
  ft.jump({
    direction = "forward"
    offset = "post",
    pattern = "\\v[()]",
    -- If you don't want to jump post ) that is the last character on the line.
    -- use this pattern: "\\v((|\\)$@!)"
  })
end)

-- Jump backward inside / outside round brackets.
vim.keymap.set({"n", "x", "o"}, "S", function()
  ft.jump({
    direction = "backward",
    offset = "post",
    pattern = "\\v[()]",
  })
end)
Jump to a number
-- Jump forward to a number.
vim.keymap.set({"n", "x", "o"}, "s", function()
  ft.jump({
    direction = "forward"
    offset = "none",
    pattern = "\\v\\d+",
  })
end)

-- Jump backward to a number.
vim.keymap.set({"n", "x", "o"}, "S", function()
  ft.jump({
    direction = "backward",
    offset = "none",
    pattern = "\\v\\d+",
  })
end)

API Functions

  • jump - Perform a jump to a character or a predefined pattern.
  • repeat_forward - Repeat last saved jump forward.
  • repeat_backward - Repeat last saved jump backward.
jump option Default Possible Description
direction "forward" "forward", "backward" Direction to jump
pattern nil (wait for a user input) any vim pattern Pattern to jump
offset "none" "pre", "none", "post" Offset to a character / pattern
save_for_repetition pattern == nil true, false Save the jump for repeat_forward and repeat_backward

Api usage example:

local ft = require("improved-ft")

vim.keymap.set({"n", "x", "o"}, ")", ft.repeat_forward)
vim.keymap.set({"n", "x", "o"}, "(", ft.repeat_backward)

vim.keymap.set({"n", "x", "o"}, "s", function()
  ft.jump({
    direction = "forward",
    offset = "none",
    pattern = "\\M=",
    save_for_repetition = false,
  })
end)

vim.keymap.set({"n", "x", "o"}, "S", function()
  ft.jump({
    direction = "backward",
    offset = "none",
    pattern = "\\M=",
    save_for_repetition = false,
  })
end)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 99.4%
  • Shell 0.6%