kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
3.18k stars 62 forks source link

`move_cursor = false` doesn't work when adding surrounds #91

Closed rafamadriz closed 2 years ago

rafamadriz commented 2 years ago

If this is a general question about the plugin or a point of confusion on a feature, please check the wiki before opening a new discussion post.

Checklist

Describe the bug When adding surrounds with move_cursor = false, the cursor position goes to the beginning of surround. This only happens when adding. Changing and deleting works as expected.

To Reproduce

  1. nvim -nu minimal.lua
  2. try to add surrounds
local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
    local path_sep = on_windows and "\\" or "/"
    local result = table.concat({ ... }, path_sep)
    return result
end

vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local function load_plugins()
    require("packer").startup({
        {
            "wbthomason/packer.nvim",
            "kylechui/nvim-surround",
        },
        config = {
            package_root = package_root,
            compile_path = compile_path,
        },
    })
end

_G.load_config = function()
    require("nvim-surround").setup({
        keymaps = {
            insert = "sa",
            insert_line = "saa",
            visual = "s",
            delete = "sd",
            change = "sc",
        },
        highlight_motion = {
            duration = 0,
        },
        move_cursor = false,
    })
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
    load_plugins()
    require("packer").sync()
    vim.cmd([[autocmd User PackerComplete ++once lua load_config()]])
else
    load_plugins()
    require("packer").sync()
    _G.load_config()
end

Expected behavior when adding surrounds with move_cursor = false, the cursor should keep its original position

Additional context Documentation: https://github.com/kylechui/nvim-surround/blob/2200f7275e19aea608f33872680e25ee687cfcb3/doc/nvim-surround.txt#L225

kylechui commented 2 years ago

Thanks for the bug report! I appreciate you taking the time to make this project better