folke / flash.nvim

Navigate your code with search labels, enhanced character motions and Treesitter integration
Apache License 2.0
2.47k stars 33 forks source link

feature: line jump with hints on the same column #214

Closed shadyalfred closed 1 year ago

shadyalfred commented 1 year ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

Showing the labels at the beginning of the line can be hard to follow specially when the lines are indentated and there is a big gap of space between the label hint and the start of the text in the line.

Describe the solution you'd like

Something like this image

IndianBoy42 commented 1 year ago

In the example code for line jumps label = { after = { 0, 0 } }, the tuple is the offset from the match to show the label, can you try changing the first 0 based on vim.api.nvim_win_get_cursor to get it to render at the same column as the cursor?

shadyalfred commented 1 year ago

Good idea, @IndianBoy42!

local col = vim.api.nvim_win_get_cursor(0)[2]

flash.jump({
  ...
  label = {
    before = { 0, col },
  },
})

image

The label is shown in the correct position, but jumping to it moves the cursor to the beginning of that line which is a bit disorienting.

shadyalfred commented 1 year ago

This works great!

local col = vim.api.nvim_win_get_cursor(0)[2]

flash.jump({
  ...
  label = {
    before = { 0, col },
  },
})

vim.api.nvim_input(col .. 'l')
IndianBoy42 commented 1 year ago

https://github.com/folke/flash.nvim/blob/967117690bd677cb7b6a87f0bc0077d2c0be3a27/README.md?plain=1#L160

You can also use opts.jump.offset

shadyalfred commented 1 year ago

Yes, I've found out about it after closing the issue. Also disabling the search highlight because it was confusing.

-- Move to lines beneath the cursor
local col = vim.api.nvim_win_get_cursor(0)[2]

flash.jump({
  jump = {
    offset = col,
  },
  search = {
    mode = 'search',
    max_length = 0,
    forward = true,
    wrap = false,
    multi_window = false,
  },
  pattern = '^',
  label = {
    before = { 0, col },
  },
  highlight = {
    matches = false,
  },
})
-- move to lines above the cursor
local col = vim.api.nvim_win_get_cursor(0)[2]

flash.jump({
  jump = {
    offset = col,
  },
  search = {
    mode = 'search',
    max_length = 0,
    forward = false,
    wrap = false,
    multi_window = false,
  },
  pattern = '^',
  label = {
    before = { 0, col },
  },
  highlight = {
    matches = false,
  },
})