.emacs配置如下:
(defun qiang-comment-dwim-line (&optional arg) "Replacement for the comment-dwim command." (interactive "*P") (comment-normalize-vars) (if (and (not (region-active-p)) (not (looking-at "[ \t]*$"))) (comment-or-uncomment-region (line-beginning-position) (line-end-position)) (comment-dwim arg))) (global-set-key (kbd "C-;") 'qiang-comment-dwim-line)
备注:
使用Ctrl+; 组合键,当光标放在行的始端,或者行的中间位置,即为注释该行代码
当光标放在行的末端,即为给该行代码添加注释。
效果如下图:
参考链接: