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

发布于 2024-09-02 09:20:07 字数 48 浏览 5 评论 0原文

我想询问普通 ESS/R 用户他们经常使用哪些键绑定以及使用 ESS/R 的技巧。

I would like to ask regular ESS/R users what key bindings do they use frequently and tips on using ESS/R.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

千寻… 2024-09-09 09:20:07

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

C-tab 在 R 命令行和文件之间切换(类似于 josh 答案,但速度更快):

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

Control 和向上/向下箭头键可搜索与您已输入的内容相匹配的历史记录:

(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)

Comment-使用 Cd 或 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 文档中提供了更多有用的快捷方式。

I have set several shortcuts in my .emacs file. The most useful are:

C-tab to switch between the R command line and the file (similar to josh answer, but much faster):

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

Control and up/down arrow keys to search history with matching what you've already typed:

(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)

Comment-uncomment a selected region with C-d or 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)

Also I've also enabled CUA mode (from options menu) and reconfigured quite a lot of shortcuts to require only two keystrokes (instead of four in standard mode):

;; 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)

You will find many more useful shortcuts in ESS documentation.

爱你是孤单的心事 2024-09-09 09:20:07

Cc Cz ess-switch-to-end-of-ESS

可以很好地从您正在编辑 foo.R 的源文件跳转到 R 控制台

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

is nice to jump from your source file that you are editing foo.R to the R console

铁轨上的流浪者 2024-09-09 09:20:07

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

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

I found this link to be extremely helpful. It provides elisp code to make Shift+Enter do many common tasks in a context dependent fashion.

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

瘫痪情歌 2024-09-09 09:20:07

很棒的东西,已经用了很多年了。不幸的是,截至 2013 年 11 月 15 日,由于 EMACS 的更改,取消注释键绑定可能无法工作(我认为,至少在我加载最新版本之前它可以工作)。这是因为默认的取消注释函数有 3 个参数,但上面定义的参数有 2 个。解决此问题的最佳方法是简单地从代码中删除取消注释函数并保留键绑定,因此它使用默认的取消注释函数。或者换句话说,只需使用这个:

  • (define-key ess-mode-map (kbd "Cd") 'comment-region)
  • (define-key ess-mode-map (kbd "CSd") 'uncomment-region)

Great stuff, have been using it for ages. Unfortunately as of 15-11-2013 the uncomment key binding may not work due to EMACS changes (I think, at least it was working before I loaded the latest version). This is because the default uncomment function has 3 arguments but the one defined above has 2. The best way to fix this is to simply delete the uncomment function from the code and retain the keybinding, so it uses the default uncomment function. Or in other words just use this:

  • (define-key ess-mode-map (kbd "C-d") 'comment-region)
  • (define-key ess-mode-map (kbd "C-S-d") 'uncomment-region)
長街聽風 2024-09-09 09:20:07

ESS R 控制台中的 Mn 和 Mp 用于下一个/上一个命令。

M-n and M-p in the ESS R console for next/previous command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文