blob: 80b0b776982bb8a5563c93dfc083943e3a09cfef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
function reverse_current_word()
local line = vim.fn.getline('.')
local current_word = vim.fn.expand('<cword>')
local start_index = vim.fn.col('.') - #current_word + 1
local reversed_word = current_word:reverse()
local reversed_line = line:sub(1, start_index -1)..reversed_word..line:sub(start_index+#current_word)
P(reversed_line)
vim.fn.setline('.', reversed_line)
end
vim.api.nvim_command('command! -range=% ReverseWord :<line1>,<line2>lua reverse_current_word()')
-- testing
|