Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion doc/nvui.txt
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,23 @@ It's preferred to put the dofile code in your plugin's config func
------------------------------------------------------------------------------
7.2 Renamer *nvui.lsp.renamer*

This is a function will will rename variable under cursor
This function renames the variable under the cursor.
>lua
require "nvchad.lsp.renamer"()

UI can be customized by passing a table of options to this function. Defaults
are listed in the example.
>lua
require "nvchad.lsp.renamer"({
border = "single", -- see :h winborder for additional options
border_hl_group = "Removed",
right_padding = 15,
title = "Renamer",
title_hl_group = "@comment.danger",
show_original = true, -- set to false if you don't want to autofill
allow_normal = false, -- set to true to access normal in renamer prompt
})

==============================================================================
8. Colorify *nvui.colorify*

Expand Down
36 changes: 29 additions & 7 deletions lua/nvchad/lsp/renamer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,55 @@ local function get_symbol_to_rename(cb)
end
end

return function()
return function(opts)
get_symbol_to_rename(function(to_rename)
local buf = api.nvim_create_buf(false, true)

local default_opts = {
border = "single",
right_padding = 15,
title = "Rename",
title_hl_group = "@comment.danger",
border_hl_group = "Removed",
show_original = true,
allow_normal = false,
}
opts = vim.tbl_deep_extend('force', default_opts, opts or {})

local winopts = {
height = 1,
style = "minimal",
border = "single",
border = opts.border,
row = 1,
col = 1,
relative = "cursor",
width = #to_rename + 15,
title = { { " Renamer ", "@comment.danger" } },
width = #to_rename + opts.right_padding,
title = { { " " .. opts.title .. " ", opts.title_hl_group } },
title_pos = "center",
}

local win = api.nvim_open_win(buf, true, winopts)
vim.wo[win].winhl = "Normal:Normal,FloatBorder:Removed"
vim.wo[win].winhl = "Normal:Normal,FloatBorder:" .. opts.border_hl_group
api.nvim_set_current_win(win)

api.nvim_buf_set_lines(buf, 0, -1, true, { " " .. to_rename })
if opts.show_original then
api.nvim_buf_set_lines(buf, 0, -1, true, { " " .. to_rename })
else
api.nvim_buf_set_lines(buf, 0, -1, true, { " " })
end

vim.bo[buf].buftype = "prompt"
vim.fn.prompt_setprompt(buf, "")

vim.api.nvim_input "A"

vim.keymap.set({ "i", "n" }, "<Esc>", function()
local modes
if opts.allow_normal then
modes = { "n" }
else
modes = { "n", "i" }
end
vim.keymap.set(modes, "<Esc>", function()
api.nvim_buf_delete(buf, { force = true })
end, { buffer = buf })

Expand Down
17 changes: 17 additions & 0 deletions nvchad_types/chadrc.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.