I want to replace the selected Text (in Visual-Mode) with the current Date.
Currently I am trying to call a cmd and then use the 'change' method.
keymap.set("x", "<leader>nf", function()
vim.cmd(string.format("insert\n%s", os.date("%d.%m.%Y")))
end)
All it does right now is to insert the Date in the line above the selection, not deleting it.
You can use a custom function you need to work with row and column of a selection of a buffer to make it happen. Other option is using the change block from visual selection. See
h v_cReplace visual selection with date (not
v_c)This solution fully removes all text from a selection and inserts a date
When selection is done you can press
\in visual mode to change to date.Insert into visual block keeping trailing text
This insert date into visual selection but keeps everything in v-block thats after the inserted date.
Use
v_cSee
:h v_cyou can replace text by entering c after selecting a visual block. If you use c while in visual mode followed by\the function below replaces it. Notice this is bound to insert mode and not visual. More keystrokes than the earlier solution but maybe less edgecases.Consider adding leader key to the bindings of above. use
:hto check out the methods for tweaking.Any of these should cover your needs.