How to insert date and time in vim along with a string literal?

I am new to Vim and trying to decide which can be very simple.

When I type dd and press <space> in insert mode, I want to replace it with [10-Feb-2011 10:10] . (note the square brackets around the date).

So, I managed to achieve this - :iab <expr> dd strftime("%e-%b-%Y %H:%M") , which inserts the date, but I also want it to be surrounded by square brackets.

I am using the implementation of Maemo Vim on the Nokia N900.

http://maemo.org/downloads/product/Maemo5/vim/

I would also like to know how to make this change permanent so that the acronym dd always available in all vim sessions. (writing this line to ~/.vim or something like that).

+4
source share
1 answer

In the ~ / .vimrc file:

 :iab <expr> dd strftime("[%e-%b-%Y %H:%M]") 

Note, however, that Vim uses your strftime platform, so the required line and format flags, in particular, are platform dependent.

+6
source

Source: https://habr.com/ru/post/1339130/


All Articles