From bbf1e3d1c23890c1d7ca84da706439946ef0cc30 Mon Sep 17 00:00:00 2001 From: Derek Lugowski Date: Wed, 26 Aug 2026 17:22:58 +0000 Subject: [PATCH] Add word_wrap function and keybind Creates a word_wrap function and keybind. Keybind: 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: https://git.lugowski.ca/dlugowski/neovim-config/pulls/2 --- README.md | 6 +++++- wrap_word.lua | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 wrap_word.lua diff --git a/README.md b/README.md index c2d75f4..da83be4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # neovim-config -Repo for managing my personal neovim config files. \ No newline at end of file +Repo for managing my personal neovim config files. + +## Keybinds + +ww [W]rap [W]ord with user supplied characters. \ No newline at end of file diff --git a/wrap_word.lua b/wrap_word.lua new file mode 100644 index 0000000..63c669e --- /dev/null +++ b/wrap_word.lua @@ -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%sP', param, param, move_cmd) + + vim.cmd('normal! ' .. vim.api.nvim_replace_termcodes(cmd, true, true, true)) +end + +vim.keymap.set('n', 'ww', wrap_word, { desc = '[W]rap [W]ord with character(s).' }) \ No newline at end of file