Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling user commands with '<,'> range will change cursor to line1, 0 #29448

Closed
haolian9 opened this issue Jun 22, 2024 · 1 comment
Closed
Labels
closed:question issues that are closed as usage questions

Comments

@haolian9
Copy link

haolian9 commented Jun 22, 2024

Problem

i'm seeing no mention about that behavior in documents, and no user-land functionality relying on it. but this behavior make it impossible to know what the original cursor is just before calling an usercmd, so i think it's a bug.

the reason i need the original cursor in an usercmd is i want to open a floating window based on the cursor.
the workaround i'm currently using is binding the callback to a keymap rhs instead, but personally i prefer to use an usercmd with meaningful name rather than a lhs which is hard to remember relatively.

Steps to reproduce

  • test.lua
--[[
  2
  3
  4
  5
  6
  7
  8
  9
  10
]]

local api = vim.api

vim.go.showmode = false

api.nvim_create_user_command("Foo", function(args)
  local cursor = api.nvim_win_get_cursor(0)
  print(string.format("cursor=%d,%d, line1=%d, line2=%d, range=%s", cursor[1], cursor[2], args.line1, args.line2, args.range))
end, { nargs = 0, range = true })

api.nvim_set_keymap("x", "foo", "", {
  noremap = true,
  callback = function()
    local cursor = api.nvim_win_get_cursor(0)
    print(string.format("cursor=%d,%d", cursor[1], cursor[2]))
  end,
})
  • nvim --clean -u NONE +'source test.lua' test.lua
  • 2ggVwjj # cursor's at 4,2 now
  • foo says cursor's at 4,2
  • :'<,'>Foo says cursor's at 2,0

Expected behavior

calling an usercmd with range wont change the cursor

Neovim version (nvim -v)

nvim 0.10

Vim (not Nvim) behaves the same?

N/A

Operating system/version

archlinux

Terminal name/version

st 0.9.2

$TERM environment variable

st-256color

Installation

pacman

@haolian9 haolian9 added the bug issues reporting wrong behavior label Jun 22, 2024
@zeertzjq zeertzjq added documentation bug issues reporting wrong behavior closed:question issues that are closed as usage questions and removed bug issues reporting wrong behavior documentation labels Jun 22, 2024
@zeertzjq
Copy link
Member

:h operator

After applying the operator the cursor is mostly left at the start of the text
that was operated upon.

@zeertzjq zeertzjq closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:question issues that are closed as usage questions
Projects
None yet
Development

No branches or pull requests

2 participants