开发者

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

开发者 https://www.devze.com 2023-02-09 09:51 出处:网络
I\'m new to Vim and trying to solve what might just be a very basic thing. When I type dd and press <space> in insert mode, I want it to be replaced with [10-Feb-2011 10:10]. (notice the square

I'm new to Vim and trying to solve what might just be a very basic thing.

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

So, far I'v开发者_如何转开发e been able to achieve this - :iab <expr> dd strftime("%e-%b-%Y %H:%M") which inserts date, but I also want it to be surrounded by square brackets.

I'm using Maemo's implementation of Vim on Nokia N900.

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

I'd also like to know how to make this change persistent so that the dd abbreviation is always available in all sessions of vim. (writing this line in ~/.vim or something like this).


In your ~/.vimrc file:

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

Note however that Vim uses your platform's strftime so the string it takes and the format flags in particular are platform-dependent.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号