diff options
Diffstat (limited to 'lua/alpha/scratchs/sample.lua')
| -rw-r--r-- | lua/alpha/scratchs/sample.lua | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lua/alpha/scratchs/sample.lua b/lua/alpha/scratchs/sample.lua index a2d783e..80b0b77 100644 --- a/lua/alpha/scratchs/sample.lua +++ b/lua/alpha/scratchs/sample.lua @@ -1,12 +1,14 @@ -local scandir = require("plenary.scandir") - - +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 -local dirs = scandir.scan_dir( - { "/home/alpha/code/php" }, - { depth = 1, only_dirs = true } -) +vim.api.nvim_command('command! -range=% ReverseWord :<line1>,<line2>lua reverse_current_word()') -for _, dir in ipairs(dirs) do - P(vim.fs.basename(dir)) -end +-- testing |