From 26e5a3d12e4aa75a297848e40be6146c65b70479 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Tue, 2 Jan 2024 23:50:36 +0800 Subject: [PATCH] feat: emacs - copilot & docs --- home/base/desktop/editors/emacs/README.md | 75 +++++++++++++++++++ .../base/desktop/editors/emacs/doom/config.el | 9 +++ home/base/desktop/editors/emacs/doom/init.el | 4 +- .../desktop/editors/emacs/doom/packages.el | 2 + 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/home/base/desktop/editors/emacs/README.md b/home/base/desktop/editors/emacs/README.md index b4350c3e..69425cfd 100644 --- a/home/base/desktop/editors/emacs/README.md +++ b/home/base/desktop/editors/emacs/README.md @@ -14,4 +14,79 @@ After deploying this nix flake, run the following command to install or update e ```bash doom sync ``` +## Terminal Related +zellij provides a more powerful and stable terminal experience, so here is zellij's terminal shortcuts I use frequently now: + +| Action | Zellij's Shortcut | +| ------------------------- | ------------------ | +| Floating Terminal | `Ctrl +

+ ` | +| Horizontal Split Terminal | `Ctrl +

+ ` | +| Vertical Split Terminal | `Ctrl +

+ ` | + +## Visual Modes + +The same as neovim/vim: + +| Action | Shortcut | +| ------------------------ | ---------------------------------------- | +| Toggle visual mode | `v` | +| Toggle visual block mode | ` + v` (select a block vertically) | + +## Text Manipulation + +- Add at the end of multiple lines: `:normal A` + + - Execublock: `:A` + + - visual block mode(ctrl + v) + - Append text at the end of each line in the selected block + - If position exceeds line end, neovim adds spaces automatically + +- Delete the last char of multivle lines: `:normal $x` + + - Execute `$x` on each line + - visual mode(v) + - `$` moves cursor to the end of line + - `x` deletes the character under the cursor + +- Delete the last word of multiple lines: `:normal $bD` + - Execute `$bD` on each line + - visual mode(v) + - `$` moves cursor to the end of line + - `b` moves cursor to the beginning of the last word + - `D` deletes from cursor to the end of line + +## Splitting and Buffers + +| Action | Shortcut | +| --------------------- | ------------- | +| Next Buffer (Tab) | `]b` | +| Previous Buffer (Tab) | `[b` | +| Save all buffers(Tab) | ` + b + S` | + +## Editing and Formatting + +| Action | Shortcut | +| ----------------------------------------------------- | -------------- | +| Format Document | ` + cf` | +| Code Actions | ` + ca` | +| Rename | ` + cr` | +| Opening LSP symbols | ` + cS` | +| Comment Line(support multiple lines) | ` + /` | +| Open filepath/URL at cursor | `gf` | +| Find files by keyword in path | ` + ` | +| Grep string in files (vertico + ripgrep) | ` + sd` | + +## Search & replace + +``` bash +SPC s p foo C-; E C-c C-p :%s/foo/bar/g RET Z Z +``` + +1. `SPC s p`: search in project +1. `foo`: the keyword to search +1. `C-; E`: exports what you’re looking at into a new buffer in grep-mode +1. `C-c C-p` to run wgrep-change-to-wgrep-mode to make the search results writable. +1. `:%s/foo/bar/g RET`: replace in the current buffer(just like neovim/vim) +1. `Z Z`: to write all the changes to their respective files diff --git a/home/base/desktop/editors/emacs/doom/config.el b/home/base/desktop/editors/emacs/doom/config.el index 9746b74f..de384eb4 100644 --- a/home/base/desktop/editors/emacs/doom/config.el +++ b/home/base/desktop/editors/emacs/doom/config.el @@ -74,3 +74,12 @@ ;; ;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how ;; they are implemented. + +;; accept completion from copilot and fallback to company +(use-package! copilot + :hook (prog-mode . copilot-mode) + :bind (:map copilot-completion-map + ("" . 'copilot-accept-completion) + ("TAB" . 'copilot-accept-completion) + ("C-TAB" . 'copilot-accept-completion-by-word) + ("C-" . 'copilot-accept-completion-by-word))) diff --git a/home/base/desktop/editors/emacs/doom/init.el b/home/base/desktop/editors/emacs/doom/init.el index ebc3164d..42076053 100644 --- a/home/base/desktop/editors/emacs/doom/init.el +++ b/home/base/desktop/editors/emacs/doom/init.el @@ -21,7 +21,7 @@ ;;layout ; auie,ctsrnm is the superior home row :completion - company ; the ultimate code completion backend + (company +childframe) ; the ultimate code completion backend ;;helm ; the *other* search engine for love and life ;;ido ; the other *other* search engine... ;;ivy ; a search engine for love and life @@ -91,7 +91,7 @@ ;; debugger ; FIXME stepping through code, to help you add bugs ;;direnv (docker +lsp) - ;;editorconfig ; let someone else argue about tabs vs spaces + editorconfig ; let someone else argue about tabs vs spaces ;;ein ; tame Jupyter notebooks with emacs (eval +overlay) ; run code, run (also, repls) ;;gist ; interacting with github gists diff --git a/home/base/desktop/editors/emacs/doom/packages.el b/home/base/desktop/editors/emacs/doom/packages.el index 364e6e9b..0e1be04f 100644 --- a/home/base/desktop/editors/emacs/doom/packages.el +++ b/home/base/desktop/editors/emacs/doom/packages.el @@ -5,6 +5,8 @@ ;; on the command line, then restart Emacs for the changes to take effect -- or ;; use 'M-x doom/reload'. +(package! copilot + :recipe (:host github :repo "copilot-emacs/copilot.el" :files ("*.el" "dist"))) ;; To install SOME-PACKAGE from MELPA, ELPA or emacsmirror: ;; (package! some-package)