vim - 在一些单词之后在当前行中插入时间戳?

时间:2017-01-07 05:05:29

标签: vim

我希望在当前行中插入时间戳,而不会破坏该行中的内容。我已阅读此post。基本上它暗示:1)。 !r date插入下一行; 2)。 !!date清除当前行并插入时间戳。

4 个答案:

答案 0 :(得分:2)

您只需要映射 F3

inoremap <special> <F3> <c-r>=strftime('%c')<CR>

这样,无论何时按 F3 按钮,它都会在插入模式期间将时间戳插入当前位置。

说明:

[i][noremap] [<special>] [<F3>] [<c-r>=strftime('%c')<CR>]
 |   |          |          |      |
 |   |          |          |      |
 |   |          |          |      |---> Whenever you press <F3> button it 
 |   |          |          |      |---> will execute this part
 |   |          |          |      |---> it is like pressing ctrl-r 
 |   |          |          |      |---> then pressing = and typing
 |   |          |          |      |---> strftime('%c') and then 
 |   |          |          |      |---> typing enter (<cr>) for execution
 |   |          |          | 
 |   |          |          |---> The key that you want to map
 |   |          |
 |   |          |----> This argument is for avoiding side effect of 'cpoption'
 |   |
 |   |-----> The  mapping (noremap) is not recursive
 |   |
 |   |-----> It means that it doesn't care of other mappings 
 |   
 |---------> (i) for insert-mode (n) for normal-mode (c) for command-mode ...

有关详情,请参阅:help map.txt

答案 1 :(得分:1)

iab idate <c-r>=strftime("%c")<cr>

无需使用任何快捷方式,只需输入“idate”或您选择的任何其他单词(iab代表插入模式缩写)

如果你有ultisnips插件,你可以创建一个这样的代码段:

snippet date "use tab to insert date" w
`date +%Y-%m-%d\ %H:%M` ${0]
endsnippet

答案 2 :(得分:0)

我有一组映射键,用于在我光标位置插入时间戳。

VOID ImageLoad(IMG img, VOID *v)
{

if (!IMG_IsMainExecutable(img))
    return;

ADDRINT mainExeImageLowAddr = IMG_LowAddress(img);
ADDRINT mainExeImageHighAddr = IMG_HighAddress(img);    

cout << "Image limits " << hex << mainExeImageLowAddr << " - " << mainExeImageHighAddr << endl;

for (SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec))
{   
    cout << "Section " << SEC_Name(sec) << " at addresses 0x" << hex << SEC_Address(sec) << " - 0x" << SEC_Address(sec)+SEC_Size(sec)-1 << endl;
}

}

... Image limits 400000 - 418b23 Section .interp at addresses 0x400200 - 0x40021b Section .note.ABI-tag at addresses 0x40021c - 0x40023b Section .note.gnu.build-id at addresses 0x40023c - 0x40025f Section .dynsym at addresses 0x4002c8 - 0x400eaf Section .rela.dyn at addresses 0x401618 - 0x4017c7 Section .rela.plt at addresses 0x4017c8 - 0x402157 Section .init at addresses 0x402158 - 0x40216f Section .plt at addresses 0x402170 - 0x4027df Section .text at addresses 0x4027e0 - 0x412347 Section .fini at addresses 0x412348 - 0x412355 Section .rodata at addresses 0x412360 - 0x415e86 Section .eh_frame_hdr at addresses 0x415e88 - 0x41653b Section .eh_frame at addresses 0x416540 - 0x41851b Section .dynstr at addresses 0x41851c - 0x418b23 Section .ctors at addresses 0x619000 - 0x61900f Section .dtors at addresses 0x619010 - 0x61901f Section .jcr at addresses 0x619020 - 0x619027 Section .data.rel.ro at addresses 0x619040 - 0x619a87 Section .dynamic at addresses 0x619a88 - 0x619c57 Section .got at addresses 0x619c58 - 0x619cef Section .got.plt at addresses 0x619cf0 - 0x61a037 Section .data at addresses 0x61a040 - 0x61a23f Section .bss at addresses 0x61a240 - 0x61af5f Section .gnu.conflict at addresses 0x61af60 - 0x61b6f7 Section .gnu_debuglink at addresses 0x0 - 0xf Section .gnu.prelink_undo at addresses 0x0 - 0x8ff Section .shstrtab at addresses 0x0 - 0x12d 使用,"--- datetime stamps inoremap dts <c-r>=strftime("%Y%m%d_%H%M%S")<CR> inoremap dtz <c-r>=strftime("%F %T%z")<CR> "--- date stamps inoremap ymd <c-r>=strftime("%Y%m%d")<CR> inoremap ymd- <c-r>=strftime("%Y-%m-%d")<CR> inoremap dny <c-r>=strftime("%d-%b-%Y")<CR> "--- time stamps inoremap tz <c-r>=strftime("%T%z")<CR> inoremap ts <c-r>=strftime("%H%M%S")<CR> 用于正常模式。

您的里程可能会有所不同,您的格式绝对 会有所不同。

答案 3 :(得分:0)

如SergioAraujo所建议,您可以将ultisnipsvim-snippets一起使用。 Ultisnips是代码片段引擎,而vim-snippets提供了实际的代码片段。您还可以安装自动完成deoplete来完成您的代码段。

回到您的问题,vim片段提供了几个与时间或日期相关的片段,例如datetimedatetimediso等。您可以找到他们here。输入代码段关键字后,您可以按将该代码段扩展到其全部内容。