Add word_wrap function and keybind

Creates a word_wrap function and keybind.

Keybind: <leader>ww

Allows you to type any characters you want, and the currently highlighted word will be wrapped with those characters.

Works on #1
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
2026-08-26 17:22:58 +00:00
parent da9b05df28
commit bbf1e3d1c2
2 changed files with 23 additions and 1 deletions
+5 -1
View File
@@ -1,3 +1,7 @@
# neovim-config
Repo for managing my personal neovim config files.
Repo for managing my personal neovim config files.
## Keybinds
<leader>ww [W]rap [W]ord with user supplied characters.
+18
View File
@@ -0,0 +1,18 @@
local function wrap_word()
local param = vim.fn.input 'Enter char(s) to wrap word: '
if param == '' then
return
end
local num_spaces_to_move = #param - 1
local move_cmd = ''
if num_spaces_to_move > 0 then
move_cmd = num_spaces_to_move .. 'h'
end
local cmd = string.format('ciw%s%s<ESC>%sP', param, param, move_cmd)
vim.cmd('normal! ' .. vim.api.nvim_replace_termcodes(cmd, true, true, true))
end
vim.keymap.set('n', '<leader>ww', wrap_word, { desc = '[W]rap [W]ord with character(s).' })