ESS / R的有用键盘快捷键和提示

时间:2010-05-25 00:04:45

标签: emacs r elisp ess

我想向常规的ESS / R用户询问他们经常使用的密钥绑定以及使用ESS / R的提示。

5 个答案:

答案 0 :(得分:17)

我在.emacs文件中设置了几个快捷方式。最有用的是:

C-tab在R命令行和文件之间切换(类似于josh的回答,但要快得多):

(global-set-key [C-tab] 'other-window)

控制和上/下箭头键以匹配您已输入的内容搜索历史记录:

(define-key comint-mode-map [C-up] 'comint-previous-matching-input-from-input)
(define-key comint-mode-map [C-down] 'comint-next-matching-input-from-input)

注释 - 使用C-d或C-maj-d取消注释所选区域

(defun uncomment-region (beg end)
  "Like `comment-region' invoked with a C-u prefix arg."
  (interactive "r")
  (comment-region beg end -1))

(define-key ess-mode-map (kbd "C-d") 'comment-region)
(define-key ess-mode-map (kbd "C-S-d") 'uncomment-region)

此外,我还启用了CUA模式(从选项菜单)并重新配置了很多快捷键,只需要两次击键(而不是标准模式下的四次):

;; Delete selection when pressing [delete] key
  (delete-selection-mode t)

;; ESS Mode (.R file)
  (define-key ess-mode-map "\C-l" 'ess-eval-line-and-step)
  (define-key ess-mode-map "\C-p" 'ess-eval-function-or-paragraph-and-step)
  (define-key ess-mode-map "\C-r" 'ess-eval-region)

;; iESS Mode (R console)
  (define-key inferior-ess-mode-map "\C-u" 'comint-kill-input)
  (define-key inferior-ess-mode-map "\C-w" 'backward-kill-word)
  (define-key inferior-ess-mode-map "\C-a" 'comint-bol)
  (define-key inferior-ess-mode-map [home] 'comint-bol)

;; Comint Mode (R console as well)
  (define-key comint-mode-map "\C-e" 'comint-show-maximum-output)
  (define-key comint-mode-map "\C-r" 'comint-show-output)
  (define-key comint-mode-map "\C-o" 'comint-kill-output)

;; Search with C-f / C-F (control-maj-F for backware search)
   (global-set-key "\C-f" 'isearch-forward)
   (global-set-key (kbd "C-S-f") 'isearch-backward)
   (define-key isearch-mode-map "\C-f" 'isearch-repeat-forward)
   (define-key isearch-mode-map (kbd "C-S-f") 'isearch-repeat-backward)

;; Save with C-s / C-S
  (global-set-key (kbd "C-s") 'save-buffer)
  (global-set-key (kbd "C-S-s") 'write-file)
  ;; need to redefine them for isearch mode (don't know why)
  (define-key isearch-mode-map (kbd "C-s") 'save-buffer)
  (define-key isearch-mode-map (kbd "C-S-s") 'write-file)

;; Pause = dedicate window. 
  (defun toggle-current-window-dedication ()
   (interactive)
   (let* ((window    (selected-window))
          (dedicated (window-dedicated-p window)))
     (set-window-dedicated-p window (not dedicated))
     (message "Window %sdedicated to %s"
              (if dedicated "no longer " "")
              (buffer-name))))
  (global-set-key [pause] 'toggle-current-window-dedication)

;; delete = delete
  (global-set-key [delete] 'delete-char)

;; C-b = list buffers
  (global-set-key (kbd "C-b") 'bs-show)

您会在ESS documentation中找到更多有用的快捷方式。

答案 1 :(得分:5)

C-c C-z ess-switch-to-end-of-ESS

很高兴从您正在编辑foo.R的源文件跳转到R控制台

答案 2 :(得分:2)

我发现此链接非常有用。它提供了elisp代码,使Shift + Enter能够以上下文相关的方式执行许多常见任务。

http://kieranhealy.org/blog/archives/2009/10/12/make-shift-enter-do-a-lot-in-ess/

答案 3 :(得分:2)

很棒的东西,已经使用了很长时间。不幸的是,截至2013年11月15日,由于EMACS的变化,取消注释密钥绑定可能不起作用(我认为,至少它在我加载最新版本之前工作)。这是因为默认的取消注释函数有3个参数,但上面定义的一个有2.最好的解决方法是从代码中删除取消注释函数并保留键绑定,因此它使用默认的取消注释函数。或者换句话说就是使用它:

  • (define-key ess-mode-map(kbd“C-d”)'comment-region)
  • (define-key ess-mode-map(kbd“C-S-d”)'uncomment-region)

答案 4 :(得分:0)

ESS R控制台中的M-n和M-p用于下一个/上一个命令。