Emacs

Published on 30 December 2022

TS file rename from https://discord.com/channels/789885435026604033/789890622424219658/931962294903144448
If you would scroll a little bit up in the msgs you would find a link (from ajit, me) of a lua nvim implementation
Only thing being you need to code in a way to delete old file (as on rename a new file is created) ← double check this

Independent buffers for same file https://youtu.be/Ey54ovJUdQ4?t=887

Buffers, windows and frames https://www.oreilly.com/library/view/learning-gnu-emacs/0596006489/ch04.html

zc and zo work to fold code. to fold jsx tags, there is <C-c><C-f>. To go to bracket pair, use %. To go to tag pair, there is <C-c><C-n>.
Update: with matchit installed, all one would need is %.

To get value of a variable, use <C-h>v and type in the variable’s name.

Commands like :!sort, :noh, :read .bashrc are still supported.

to switch to a buffer, use <C-x>b.

In magit, sometimes j command is overriden by vim keys. Use h to bring help first and then type the key. Alternatively, use <C-z> to toggle to Emacs mode.

Apart from <C-n> <C-p>, if fn overload is available (shown by 1/3), use alt+n alt+p to toggle b/w them.
^ C-j and C-k also works too

gd and gD to definition and references. SPC c t will go to type definition. there’s SPC c i to go to implementations. In

const fzf = new Fzf();
fzf.find();

try using gd and SPC c t on fzf which is in 2nd line to see the difference.

Right click, hover, mouse click, drag to resize splits (windows) works in emacs.

Don’t use lsp symbols for a file, use <SPC> s i or g O instead. LSP stuff is under <SPC> c.

There is diff-buffer-with-file under M-x to see modifications done after last save.

https://emacs.stackexchange.com/a/189 ← there is find alternate file option in emacs. Not sure how to use it
^ Also, this question is actually related to reloading the file when it changes on file system. the process is called reverting in emacs https://emacs.stackexchange.com/a/355.

To exit a command or a menu, while Esc works, another way is to <C-g>. More at https://blog.aaronbieber.com/2015/05/24/from-vim-to-emacs-in-fourteen-days.html. q also sometimes help you to quit buffers, info, helpers and finders.

<C-c> is like user keymapping space. also it somewhat changes depending on which file/buffer you are on.

Workspaces https://github.com/hlissner/doom-emacs/blob/develop/modules/ui/workspaces/README.org
Echo all using ctrl+shift+t
add new using ctrl+t
M-x persp or M-x workspace
^ C-c p                   ^ SPC TAB
^ this is better, gt and gT also works

nnoremap (nore) doesn’t exist because all maps are overrides. To see current key assignment command use SPC h k or C-h k and type that key. It can be a single key or key chord.
To get help on keybinding itself, see SPC h f map\!.

Might be super outdated: github.com/noctuid/evil-guide

SPC o - to open dired.

As doing ciw on stuff_l|ike_this would only affect like and not the whole variable, Doom provides cio/cao (change inner/around symbol). There are other text objects too, see https://github.com/hlissner/doom-emacs/blob/43ddb109703c25a105c4d2e156f6055ffc58181b/docs/faq.org#why-do-non-evil-users-get-expand-region-but-not-evil-users

On file watchers https://github.com/hlissner/doom-emacs/issues/6000#issuecomment-1013795522
I haven’t increased file watchers in ubuntu yet like what vscode usually suggests

On .elc files when running doom doctor, also just to make a fresh start
https://github.com/hlissner/doom-emacs/issues/4257
https://github.com/hlissner/doom-emacs/issues/4171

While gi, g;, c-o in insert mode do work, ops like alt+o, alt+h don’t.

Rather than using :noh, you can use Esc. Same for f/T motions.

Display checkmarks in org mode https://discord.com/channels/406534637242810369/484105925733646336/929169461511061525

On using special chars https://www.youtube.com/watch?v=HjUquOQtIYs

https://discord.com/channels/406534637242810369/806409569013858314/928768975138091099

To add lines below and above, there are shortcuts around 2 [ o. Search for evil newline in M-x.

% navigates to bracket pair. you can do the same using doom emacs, but using Tab is more ergonomic.
Update: with evil-matchit installed, using % is more preferrable.

From https://github.com/syl20bnr/spacemacs/issues/10502#issuecomment-404453194

(setq default-text-properties '(line-spacing 0.1 line-height 1.1))

Another option is https://github.com/tam5/font-patcher (uses fontforge, so not that good).

There is (SPC s i), while non-LSP, it also shows parent symbol (like constructor’s class name) thus it is more useful:

(evil-define-key 'normal 'global (kbd "SPC j") 'consult-lsp-file-symbols)

I don’t think i would ever use it, also seems like (SPC s s) just does exactly this:

(evil-define-key 'normal 'global (kbd "SPC l") 'consult-line)

Didn’t automatically detected projects for me
Also need to add a tmp wksp which isn’t ghq as it would be my playground:

(setq projectile-project-search-path '("~/ghq"))

Use M-<number> to directly insert
or use C-<number>j to navigate to the item in completion

(setq company-show-quick-access t)

If you want to expand snippet on TAB, disable https://github.com/hlissner/doom-emacs/blob/f73ae8eee176b46fc8d02d8702d2da9bc25b3472/modules/config/default/%2Bevil-bindings.el#L145
and use yas/expand instead (find it on M-x).

https://github.com/kana/vim-textobj-user for ci, (change inner comma)

Yanked from browser, deleted stuff on emacs and now used paste but it pasted the deleted text? Fear not, C-p (evil-paste-pop) is here. (There’s also C-n but it is to navigate forward in paste history.)

Don’t use visual mode to select and yank. your cursor will also won’t move after yanking if you are on normal mode (see https://github.com/emacs-evil/evil/issues/727). If you are on fn ending bracket, you can do y<tab> to yank content inside {} including brackets, otherwise do yV<tab> to yank whole fn.

Use gss to go to specific row and column.

(map! :nvo "gj" #'evilem-motion-next-line)
(map! :nvo "gk" #'evilem-motion-previous-line)

^^ I could’ve used these last two bindings but I myself want to encourage the use of gss.

To get typewriter mode, see https://github.com/zkessin/centered-cursor-mode (see also the repo where it is forked from)
https://two-wrongs.com/centered-cursor-mode-in-vanilla-emacs and https://www.reddit.com/r/emacs/comments/efywlx/scrollpreservescreenposition_screws_up/
https://stackoverflow.com/questions/9221429/how-to-change-the-position-of-the-cursor-in-centered-cursor-mode-in-emacs

When using SPC SPC and on a file list, use C-; to see all available options for it (embark shows these options). While options list (which-key) is opened you can use C-h to search and select an option. I still do not know how to see next list of options (2/3) for example through which key.
There’s also https://hungyi.net/posts/doom-emacs-search-replace-project/ ← for mass search and replace.

golang does auto import, but we also have M-x go impor. (Past Ajit might meant import, not impor).

To swap lines, use M-arrow up/down. See https://discord.com/channels/406534637242810369/406554085794381833/936273837471985716

When searcing a project for text with SPC s p, is there a way to limit to a specific file extension?

You could use foo -- -g*.org (well, any ripgrep flags)
Don’t quote the glob term.

#foo#org will work too, but will produce more false positives
The Y in #X#Y is matched against all output, including file names.

foo -- ARGS
ARGS = ripgrep arguments

#foo#bar
bar = vertico/consult is doing the filtering

Indentation is detected using dtrt-indent-mode https://discord.com/channels/406534637242810369/406554085794381833/935927391430266900
Just so you know, as it looks like you already solved this issue but in C mode (and I believe even C-like modes, which is basically several modes) there’s a variable called c-indent-tabs-mode that supersedes the standard indent-tabs-mode. In fact, you should check whatever modes you use to see if and what formatting and indentation functionality they use, override, or downright ignore the standard settings of.

Get https://github.com/sgur/vim-textobj-parameter functionality!!
change fn arg using: ci, (vim) → cia (emacs) & ca,caa
This is provided by the evil-args package
There’s also gsa/gsA to move b/w args

Still don’t know what can be done for https://github.com/Julian/vim-textobj-variable-segment
Maybe you can modify this? https://emacs.stackexchange.com/questions/14439/evil-package-alternative-for-motion-through-camelcase-words
And also taking help from evil-args
https://implementations-list.ourproject.narkive.com/Qqj7dN6H/evil-mode-and-camelcase-movement

For changing case, there are:
https://github.com/ninrod/evil-string-inflection
https://github.com/strickinato/evil-briefcase

For future use https://github.com/meain/evil-textobj-tree-sitter

Also redir to new buffer on SPC e maybe
Make ls+ work (show only modified buffers, it’s a vim things)
How to only navigate through errors when warnings are shown too?
List all errors
List search results and filter, remove, navigate (gf and gF)
While searching, skip to next file result
Which key embark see next shortcuts

Also a way to store ripgrep results in a folder for easy search on them like vim-bqf (there is embark-export but it’s somewhat clunky)
https://protesilaos.com/codelog/2021–01–09-emacs-embark-extras/
https://karthinks.com/software/fifteen-ways-to-use-embark/
https://www.reddit.com/r/emacs/comments/osx5t9/recent_embark_developments_detailed_action/

While in insert mode, what key do you press to expand a snippet? Asking because currently, pressing TAB goes through autocompletion list
https://discord.com/channels/767406463265538068/767410250608934932/936295355811762286
https://joaotavora.github.io/yasnippet/snippet-expansion.html

Live file change like when using find references when navigating

Disable ESC on quick jk press https://github.com/hlissner/doom-emacs/issues/1946#issuecomment-546012335
that link above also mentions after! syntax
usually it’s not safe to disable an internal pkg this way https://github.com/hlissner/doom-emacs/issues/2280#issuecomment-569976805
another way at https://discord.com/channels/406534637242810369/936355238582050887/936355552794120213 (← if this doesn’t open, just copy and search for the link above)

C-h b b ← describe bindings, is context aware | there’s also M-x describe-mode

(defun do-the-thing ()
  (interactive)
  (select-window (split-window-below))
  (+lookup/documentation))

(map! :n "C-k" #'do-the-thing)

K key may give info alongwith type info when used at a point (symbol)
others ctrl ], K, gd, c-i, c-o, c-t, g-; , g-, ← vim

Use editorconfig for indentation
https://discord.com/channels/406534637242810369/406554085794381833/929001849028239380

Write :noa w equivalent to save without format-all

Install treesitter
https://github.com/meain/evil-textobj-tree-sitter
and treesitter powered comments, see https://github.com/numToStr/Comment.nvim

On go and flycheck https://discord.com/channels/406534637242810369/406554085794381833/936968917006577724

c-h v major-mode to see major mode, other way which somewhat gives incorrect results is c-h b m

M-/ in insert mode to auto-complete from buffer ← it’s prety powerful when used correctly
See https://emacs.stackexchange.com/questions/15179/company-backend-for-words-inside-the-buffer
and https://emacs.stackexchange.com/questions/2762/jump-to-documentation-buffer-with-company-mode

C-x C-f in insert modes completes file-names.
There’s also company-files backend.

Emacs has alt+q to wrap comment, and apparently, it wrap only comment if there is source code just below it (looking at you vim’s gq and gQ)
Still, not as smart as vscode comment plugin.

Windows term + emacs https://discord.com/channels/406534637242810369/930877409929068564/935956670780170310

Doom works fine for me with emacs-ng after deleting .emacs.d and re-cloning/reinstalling Doom. You might be able to get way with just deleting .emacs.d/.local/straight and running doom build again.

rm -rf ~/.emacs.d/.local/straight && doom sync

M-j to indent to new line is pretty useful if you want to format code a little (or comment even).

If getting error on describe variable or describe key
https://discord.com/channels/406534637242810369/406554085794381833/937289467016925234

Apart from using SPC < to list all buffers, one can also use :b <partial filename><tab>

https://stackoverflow.com/questions/22817120/how-can-i-save-evil-mode-vim-style-macros-to-my-init-el

https://www.google.com/search?client=firefox-b-d&q=Indirect+buffers
https://noelwelsh.com/posts/doom-emacs/

https://news.ycombinator.com/item?id=22130840
https://news.ycombinator.com/item?id=22145211
https://news.ycombinator.com/item?id=22132419
https://news.ycombinator.com/item?id=29736366
https://news.ycombinator.com/item?id=28091520
https://news.ycombinator.com/item?id=29726398
https://github.com/elken/.doom.d
https://news.ycombinator.com/item?id=22129636
https://news.ycombinator.com/item?id=29239452
https://news.ycombinator.com/item?id=26521186

https://www.reddit.com/r/emacs/comments/f3o0v8/anyone_have_good_examples_for_transient/
https://karthinks.com/software/avy-can-do-anything/
https://hungyi.net/
https://lars.ingebrigtsen.no/2021/10/28/emacs-emojis-a-%e2%9d%a4%ef%b8%8f-story/
https://docs.doomemacs.org/latest/

https://www.evanlouie.com/gists/go/docs/doom-emacs-setup
https://stackoverflow.com/questions/61998389/full-ide-features-support-for-golang-in-doom-emacs

https://emacs.stackexchange.com/questions/3149/how-to-non-interactively-dump-list-of-open-buffers-associated-filenames-and-sav

https://www.reddit.com/r/emacs/comments/ol2luk/from_ivy_counsel_to_vertico_consult/

https://www.reddit.com/r/emacs/comments/coti6b/tring_to_get_dapdebug_to_work_with_golang/

word wrap.
^^^ toggle word wrap not working

voicemail in inbound

in emacs mode, many time j/k and alt-p/n can work, and c-n/p work like j/k of vim in vc-region-history

https://www.reddit.com/r/emacs/comments/9b5z79/the_built_in_version_control_is_pretty_cool/

you to toggle emacs state using C-z

https://stackoverflow.com/questions/275842/is-there-a-repeat-last-command-in-emacs/275903#275903

https://github.com/hlissner/doom-emacs/issues/5876#issuecomment-1015731238
^ on persp-mode and emacs client
https://github.com/hlissner/doom-emacs/issues/6043#issuecomment-1022717088

On multi cursors https://discord.com/channels/406534637242810369/406554085794381833/938105347778936892

(map! :n "R" #'whatever-you-want) ;; replace evil map

Fix issues w/ WSL copy https://github.com/microsoft/wslg/issues/15
Don’t upgrade using microsoft store version, otherwise you would face port issues. (See this post)

Doom provides a way to open link using gf. but you would need to enable windows interop

On invalidating caching when using magit https://emacs.stackexchange.com/a/26272

Taken from https://old.reddit.com/r/evilmode/comments/may1mp/what_is_evils_equivalent_of_vims_ctrlg/grwapi5/

M-x indirect

If you visit the wrong file unintentionally by typing its name incorrectly, type C-x C-v (find-alternate-file) to visit the file you really wanted. C-x C-v is similar to C-x C-f, but it kills the current buffer (after first offering to save it if it is modified). When C-x C-v reads the file name to visit, it inserts the entire default file name in the buffer, with point just after the directory part; this is convenient if you made a slight error in typing the name.

M-x find-alternate-file <RET> and then hitting enter is a great way to reset a file if :e(!) doesn’t work

C- a/e/w/u — start / end of line / clear word / clear line (from terminal, applies in emacs/vim too)