回答
C-u M-! date
令人難以置信的直覺:) – msandiford 2010-09-24 04:16:25
只是爲了完整:`M-!`是函數`shell-command`的鍵盤快捷鍵。所以`M-! date`將調用shell命令`date`,並將其顯示在輸出區域(minibuffer,因爲輸出足夠短以適合)。 `C-u`是一個前綴參數,它使`M-!`將其輸出放入當前緩衝區。 – ShreevatsaR 2011-09-26 05:09:03
把你的.emacs文件:
;; ====================
;; insert date and time
(defvar current-date-time-format "%a %b %d %H:%M:%S %Z %Y"
"Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")
(defvar current-time-format "%a %H:%M:%S"
"Format of date to insert with `insert-current-time' func.
Note the weekly scope of the command's precision.")
(defun insert-current-date-time()
"insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
(interactive)
(insert "==========\n")
; (insert (let() (comment-start)))
(insert (format-time-string current-date-time-format (current-time)))
(insert "\n")
)
(defun insert-current-time()
"insert the current time (1-week scope) into the current buffer."
(interactive)
(insert (format-time-string current-time-format (current-time)))
(insert "\n")
)
(global-set-key "\C-c\C-d" 'insert-current-date-time)
(global-set-key "\C-c\C-t" 'insert-current-time)
我使用類似的東西,但是我將它從C-C C-t改爲C-X C-t,因爲C-c C-t採用了org-mode的「標記TODO項目」綁定方式。對我來說,這是不幸的硬連線肌肉記憶。 :) – AssembledGhost 2012-04-10 08:55:21
`「\ C-c \ C-d」`沒有任何事情發生在我身上。實際上,當輸入'C-d'時它會刪除當前行。但我認爲爲什麼`C-c`不工作。 – Jack 2013-02-15 03:32:22
這是我剛纔寫的一個軟件包,它可以滿足您的要求。
http://github.com/rmm5t/insert-time.el/tree/master/insert-time.el
(require 'insert-time)
(define-key global-map [(control c)(d)] 'insert-date-time)
(define-key global-map [(control c)(control v)(d)] 'insert-personal-time-stamp)
您可以安裝yasnippet,這將讓你輸入「時間」和TAB鍵,並做了很多更多之外。它只是在幕後調用current-time-string
,因此您可以使用format-time-string
控制格式。
與內置模板和hippie-expand相比,yasnippet是一種資源管理器。 – 2014-07-28 01:56:30
我已經使用了這些簡短片段:
(defun now()
"Insert string for the current time formatted like '2:34 PM'."
(interactive) ; permit invocation in minibuffer
(insert (format-time-string "%D %-I:%M %p")))
(defun today()
"Insert string for today's date nicely formatted in American style,
e.g. Sunday, September 17, 2000."
(interactive) ; permit invocation in minibuffer
(insert (format-time-string "%A, %B %e, %Y")))
他們最初是從journal.el
M-1 M-來了!日期
這會導致您運行的shell命令插入到當前正在編輯的緩衝區中,而不是新的緩衝區。
謝謝,CMS!我的變化,爲它的價值 - 讓我開心就好:
(defvar bjk-timestamp-format "%Y-%m-%d %H:%M"
"Format of date to insert with `bjk-timestamp' function
%Y-%m-%d %H:%M will produce something of the form YYYY-MM-DD HH:MM
Do C-h f on `format-time-string' for more info")
(defun bjk-timestamp()
"Insert a timestamp at the current point.
Note no attempt to go to beginning of line and no added carriage return.
Uses `bjk-timestamp-format' for formatting the date/time."
(interactive)
(insert (format-time-string bjk-timestamp-format (current-time)))
)
我把這個在一個由我的.emacs使用文件名爲:
(load "c:/bjk/elisp/bjk-timestamp.el")
這既使得它更容易修改而不會冒着在我的.emacs中打破別的東西的風險,並且讓我有一個簡單的切入點,可能有一天會真正學習這個Emacs Lisp編程的全部內容。
P.S.對我的n00b技術的批評最受歡迎。
對於與已發佈內容類似的解答,以及解釋和更多擴展,例如自動打開文件並在其末尾插入當前日期(如日記),請查看Paul Ford's discussion of his emacs utilities。
對於插入日期: M-X ORG-時間戳 對於插入日期時間: C-U m的-X ORG-時間戳
可能是你可以綁定這個命令全局鍵。
組織模式的方法非常用戶友好,您可以選擇日曆中的任何日期。
這是我的承擔。
(defun modi/insert-time-stamp (option)
"Insert date, time, user name - DWIM.
If the point is NOT in a comment/string, the time stamp is inserted prefixed
with `comment-start' characters.
If the point is IN a comment/string, the time stamp is inserted without the
`comment-start' characters. If the time stamp is not being inserted immediately
after the `comment-start' characters (followed by optional space),
the time stamp is inserted with 「--」 prefix.
If the buffer is in a major mode where `comment-start' var is nil, no prefix is
added regardless.
Additional control:
C-u -> Only `comment-start'/`--' prefixes are NOT inserted
C-u C-u -> Only user name is NOT inserted
C-u C-u C-u -> Both prefix and user name are not inserted."
(interactive "P")
(let ((current-date-time-format "%a %b %d %H:%M:%S %Z %Y"))
;; Insert a space if there is no space to the left of the current point
;; and it's not at the beginning of a line
(when (and (not (looking-back "^ *"))
(not (looking-back " ")))
(insert " "))
;; Insert prefix only if `comment-start' is defined for the major mode
(when (stringp comment-start)
(if (or (nth 3 (syntax-ppss)) ; string
(nth 4 (syntax-ppss))) ; comment
;; If the point is already in a comment/string
(progn
;; If the point is not immediately after `comment-start' chars
;; (followed by optional space)
(when (and (not (or (equal option '(4)) ; C-u or C-u C-u C-u
(equal option '(64))))
(not (looking-back (concat comment-start " *")))
(not (looking-back "^ *")))
(insert "--")))
;; If the point is NOT in a comment
(progn
(when (not (or (equal option '(4)) ; C-u or C-u C-u C-u
(equal option '(64))))
(insert comment-start)))))
;; Insert a space if there is no space to the left of the current point
;; and it's not at the beginning of a line
(when (and (not (looking-back "^ *"))
(not (looking-back " ")))
(insert " "))
(insert (format-time-string current-date-time-format (current-time)))
(when (not (equal option '(16))) ; C-u C-u
(insert (concat " - " (getenv "USER"))))
;; Insert a space after the time stamp if not at the end of the line
(when (not (looking-at " *$"))
(insert " "))))
我更願意將此綁定到C-c d
。
- 1. 如何將TimeStamp(當前日期和當前時間)插入到Microsoft SQL Server表的日期時間字段中?
- 2. 如何使用vim將當前時間插入到文件中
- 3. 在Oracle SQL中:如何將當前日期和時間插入到表中?
- 4. 如何在neo4j節點中插入當前時間和日期
- 5. 使用shell腳本將當前日期/時間寫入文件
- 6. 將當前日期時間插入到審計表中
- 7. 如何使用PHP將當前日期時間放入MySQL中
- 8. 如何編寫批處理文件/ vbscript將當前日期和時間插入到AssemblyInfo文件中
- 9. 如何將日期時間插入到MySQL日期時間?
- 10. MySQL - 如何將當前日期作爲Unix時間戳插入?
- 11. EF4.1插入當前日期/時間
- 12. MySQL - 插入當前日期/時間?
- 13. 插入當前日期時間
- 14. 如何使用java將當前日期插入到mysql db
- 15. 如何使用SQL在數據庫中插入當前日期和時間?
- 16. 在MySQL/PHP中使用now()插入當前日期/時間
- 17. 如何在SQL Server 2005中插入當前日期時間
- 18. 使用NSIS將當前日期和時間作爲文件名寫入
- 19. 在SQLite數據庫中插入當前日期和時間
- 20. 在sqlite中插入當前日期和時間
- 21. 使用存儲過程將當前日期時間插入到oracle數據庫
- 22. 當前時間和日期
- 23. 如何將當前日期和時間添加到保存文件的名稱?
- 24. 如何將當前日期時間插入Sitecore電子郵件模板
- 25. 使用T-SQL將當前日期插入日期列?
- 26. 如何在Ms Access中使用c#插入當前日期/時間
- 27. 以日期時間格式插入當前日期mySQL
- 28. 使用當前日期時間將日期時間添加到數據表?
- 29. 如何在python中將當前日期時間寫入csv文件?
- 30. 使用Datetimepicker插入時間和日期
記事本中的Ctrl + G打開「轉到線」對話框,這也很有用! – cfeduke 2008-10-30 21:57:17