Skip to content

Linewise jump that preserves current column #222

Answered by ggandor
Andrew15-5 asked this question in Q&A
Discussion options

You must be logged in to vote

I also wonder if that snippet can be modified to achieve the same result.

We actually jump to each line, to get the value of the last column, and choose either the original column, or the last one on the given line (if the original is beyond that). Finally, we restore the view.

    -- Get targets.
    local saved_view = vim.fn.winsaveview()  -- <<
    local curcol = vim.fn.col('.')           -- <<
    local targets = {}
    local lnum = wininfo.topline
    while lnum <= wininfo.botline do
      local fold_end = vim.fn.foldclosedend(lnum)
      -- Skip folded ranges.
      if fold_end ~= -1 then
        lnum = fold_end + 1
      else
        if (lnum < cur_line - skip_range) or (lnum > c…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Andrew15-5
Comment options

@Andrew15-5
Comment options

Answer selected by Andrew15-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants