Learning Doom and Vim
You know what improves productivity? Mastering motions and operators.
Why Doom ?! 왜 둠으로 갈아타니?
-
크로스 플랫폼 지원 목표
-
최소 설정 최대 효과
-
2023-09-09 이 문서를 번역하고 스페이스맥스로 변경하자. 뭐 여기에 미친 사람이 아니라면 이 정도 에디팅 정보를 모으지 안을 것이다. 특히 EVIl 편집 관련해서 정말 대단한 수준의 도를 이루었다. 이것 때문에 내가 Doom 으로 옮길 수는 없다.
-
[2024-02-16 Fri 09:47] 이 문서를 마주하며 감동했다. Spacemacs 로 옮기려는 생각이 항상 있었지만 때가 되면 그렇듯. 자연스레 둠으로 가게 되었다. 하루만에 둠으로 거의 모든 것을 옮겼다. 그래도 어려움이 없음에 감사하며. 이제 배포판을 충분히 준비할 수 있다. 추가 키를 없이 기본 구성만으로 전체를 포괄하여 이해한다면 모든 것이 쉬워진다. 설정이 없어야 모두가 사용할 수 있으며 그도
Doom
evil-dot-doom 문서
Doom General
Doom is a configuration framework for Emacs tailored for Emacs bankruptcy veterans who want less framework in their frameworks. Configuration is at the same time the most fun and biggest challenge of any Emacs installation, Doom has the advantage to be a sink for several hours of digging into very specific corners of Emacs. Let's all leverage that.
Doom 은 프레임워크에서 프레임워크가 적은 것을 원하는 Emacs 파산 베테랑을 위해 맞춤화된 Emacs 용 구성 프레임워크입니다. 구성은 모든 Emacs 설치에서 가장 재미있고 가장 큰 도전 과제인 동시에, Doom 은 몇 시간 동안 Emacs 의 매우 구체적인 구석을 파헤칠 수 있는 싱크대 역할을 할 수 있다는 장점이 있습니다. 모두 이 점을 활용합시다.
General recommendations:
- Use REPL and Eshell toggle functionality:
SPC o e
=> for eshell - When
Too many open pipes
error pops up run:M-x file-notify-rm-all-watchers
SPC sj
search in the jumplistCtrl ,
find next flyspell error- Use
SPC ~
to toggle popup buffers : C-` 도 같다. - SPC ` : switch-to-previous-buffer
How to perform project-search and replace?
텍스트 검색해서 일괄 수정하는 시나리오를 설명하고 있다. 필수 시나리오다.
spc s p
launch a project text searchc-;
to runembark-act
: Spacemacs M-oE
to runembark-export
C-c C-p
to runwgrep-change-to-wgrep-mode
to make search results writable:%s/foo/bar/g
to perform a regular single file editZ Z
to write all the changes to their respective files orZ Q
to abort search and replace
Modules / Layers
Doom has several modules enabling different features across Emacs. This section attempts to document the major functionalities I rely on in a daily basis
Doom에는 여러 모듈이 있어 Emac에서 다양한 기능을 사용할 수 있습니다. 이 섹션에서는 제가 매일 사용하는 주요 기능을 문서화하려고 합니다
> 이게 다 입니까?
Search : 검색
If you press SPC
and wait for a few seconds, the which-key
panel will pop up. We can already see a couple of good search options, but the majority of the search functionality is behind SPC s
.
SPC 를 누르고 몇 초간 기다리면 which-key
패널이 나타납니다. 이미 몇 가지 좋은 검색 옵션이 표시되어 있지만 대부분의 검색 기능은 SPC s
뒤에 있습니다.
| Commands | Description | |----------|-------------------------------------------------------| | SPC + * | search for the word at point across the whole project | | SPC + ' | resume last search | | SPC + / | search in the whole project |
Git timemachine : Git 타임머신
[2024-02-16 Fri 13:00] 이건 사용 안해봤는데? 필요한가? 검토 바람.
The evil keybindings for git-timemachine are:
| Command | Function | |---------|------------------------------------| | C-k | git-timemachine-show-prev-revision | | C-j | git-timemachine-show-next-revision | | q | git-timemachine-quit | | gtY | git-timemachine-kill-revision | | gtb | git-timemachine-blame |
Doom Cheatsheet
General
spc :
: for entering a commandspc f D
: delete this filespc b m
: bookmark current buffer windowspc b RET
orspc RET
: open bookmark browser
Projects with Projectile
spc o E
to open the shell (eshell) in fullscreenspc o e
to open the shell (eshell) in a popup windowspc f r
recently visited filesspc f R
rename filespc p r
recently visited files in a project
Dired
C
to copyR
to move- Toggle
(
for simple view c
compress file
| Keybind | Description | |-------------|------------------------------| | SPC f d | Find directory with dired | | q | Exit dired buffer | | C-c C-r | Run | | C-c C-e | Rename entries with |
패키지
fd-dired, diredfl, dired-git-info, dired-rsync 가 기본 탑재. 왜?!
dirvish 도 있으나, 굳이 사용할 필요 없다.
Buffers, Windows and Basic Navigation
Buffers
spc b X
you can create a scratch buffer
Windows
spc w w
to switch windows
Workspaces
spc tab [
previous workspacespc tab ]
next workspace
Quick, horizontal movements with evil-snipe
f
and then the letter you want to navigate to,
will go backward;
will go forward after that "find"
s
to snipe (choose two letters)evil-snipe
remembers your last search. you can press;
or,
and the last search will be replayed.
] a
move forward by arg
Long distance navigation inside the file
g s spc
to use avy and going to a certain word in file- Use
t
to "teleport" the word from one place to anotherg s spc select-one-letter t select-the-correct-spot-to-teleport
Multiple cursor in Emacs with evil-multiedit
Make selections and then edit those selections interactively. You can make an edit and the changes will be reflected in all the selections
M-d
will select the current word, and again will find another occurrenceM-o
will find the occurrence upward
Many evil-mode motions/operators will have slightly different behavior while evil-multiedit
is active or the cursor is in an iedit region:
D
delete the regionC
delete to end-of-region and go into insert modeA
go into insert mode at end-of-regionI
go into insert mode at start-of-regionV
select the regionP
replace the iedit region with the contents of the clipboard
File tree
spc o p
for opening treemacs
Doom Evil Collections
- Prefix keys:
g
andz
are the ubiquituos prefix keysg
generally stands for "go" and is best used for movementsz
is used for scrolling, folding, spell-checking and more
Quitting (q, ZQ, ZZ)
In Vim, q
is for recording macros.
Vim quits with ZZ
or ZQ
. In most Emacs special modes, it stands for quitting while macros are recorded/played with <f3>
and <f4>
.
- Bind
q
andZZ
toquit-window
- Bind
ZQ
toevil-quit
Refreshing / Reverting (gr)
gr
is used for refreshing inevil-magit
,evil-mu4e
, and more.
REPL (gz)
If the mode has a Go To REPL-type command, set it to gz
Doom Works Only In Vim
Works in Vim, but seems not to work on Doom
- [ ] Global marks are preserved between sessions in Vim
- [ ] :help <doc-entry> ---- Vim docs not available :/
- [ ] :changes doesn't work
- [X]
[I
show lines with matching word under cursor- now, this binding will call
+vertico/search-symbol-at-point
function which is an improvement over Vim's default behavior due to interactivity
- now, this binding will call
- [ ] the commands
'[
, and']
does not work.- These are marks defined by Vim to jump to last yank/changed text
- we can use
goto-last-change
org;
command though
- [ ]
`0
will return you to the last file you had open before you quit vim
Doom Projects Projectile
Doom relies on Projectile to handle all project related functionalities under SPC p
prefix.
| Command | Description | |-----------|------------------------------------------------| | spc p + e | edit .dir-locals file from project | | spc p + i | invalidate project cache | | spc p + t | toggle between project implementation and test | | spc p + l | list todos | | spc p + d | see project directory files in Dired | | spc p + g | projectile-ripgrep |
Doom CORE
Doom is basically broken down into core
and modules
at a very high level. All the code in core
are related to sane defaults, Doom's foundation on package management, projects, and a feel more pieces.
Doom은 기본적으로 매우 높은 수준에서 ~코어~와 ~모듈~로 나뉘며, ~코어~의 모든 코드는 정상적인 기본값, 패키지 관리에 대한 Doom의 기반, 프로젝트 및 느낌 더 많은 부분과 관련이 있습니다.
The current statuses for each package are:
| Status | Meaning | |--------|-----------------------------------------------------| | ✅ | package kept | | ❌ | package removed | | ⚠️ | package removed, but under consideration | | ☑️ | package kept, something broke on removal | | 💠 | package kept, hard dependency of some other package |
- [✅] projectile
- [✅] which-key
- Only display on
C-h
press after a prefix
- Only display on
- [✅] ws-butler
- [✅] smartparens
- [✅] gcmh
- [✅] pcre2el
- Improve working with Emacs regexp
- [❌] highlight-numbers
- [❌] explain-pause-mode ;; top, for Emacs
- [❌] rainbow-delimiters
- [❌] project
- [❌] expand-region.el
- [❌] drag-stuff.el
- [❌] paredit
- [❌] dtrt-indent
- [❌] all-the-icons
- [❌] helpful
- [❌] restart-emacs
- [✅️️] better-jumper
- I felt the difference in my first day working without this package.
- The package seems pretty nice and the functionality is important to daily usage when coding. Jumping back and forth a definition is not as reliable without this package.
Doom MODULES
[2024-02-16 Fri 16:26] 그가 작업하는 이상. 원본 구분은 사라진다.
corfu
treesit
vertico
- [✅] vertico
- [✅] orderless
- It is possible to live without orderless and configuring
completion-styles
option to considerpartial-completion
andflex
, howeverorderless
is a lot faster. Let's keep it around. - Amazing! I learned how to use
orderless
in company completion UI. AsSPC
takes us out of completion, let's use&
as the separator. - The separator also works with
corfu
now that I ditchedcompany
for a while
- It is possible to live without orderless and configuring
- [☑️] consult
- Project search via
SPC /
was broken
- Project search via
- [⚠️] consult-dir
- [⚠️] consult-flycheck
- [⚠️] embark
- [⚠️] embark-consult
- [⚠️] consult-dir
- [✅️] wgrep
- wgrep allows you to edit a grep buffer and apply those changes to the file buffer like
sed
interactively. No need to learn sed script, just learn Emacs - example of workflow:
projectile-grep
i
:s/<pattern>/<new-pattern>/g
ZZ
- wgrep allows you to edit a grep buffer and apply those changes to the file buffer like
- [✅] marginalia
- This is useful because as there is a bug with
uniquify
andpersp-mode
used for workspaces, then I can't really know the difference for several buffers opened with the same name. Therefore, marginalia adds sufficient annotation to make this way better.
- This is useful because as there is a bug with
doom
- [❌] doom-themes
- [❌] solaire-mode
popup
Very amazing package developed by Doom team. I'm very interested in digging deeper here. Taming popup has been one of my worst skills in Emacs. I enabled +all
special buffers to be handled as popups. Very optimistic about this.
Doom 팀이 개발한 매우 놀라운 패키지입니다. 여기서 더 깊이 파고들고 싶습니다. 팝업을 길들이는 것은 제가 이맥스에서 최악의 기술 중 하나였습니다. 모든 특수 버퍼를 팝업으로 처리하도록 활성화했습니다. 매우 낙관적입니다.
+all : Enable fallback rules to ensure all temporary/special buffers (whose name begins with a space or asterix) are treated as popups.
+defaults : Enable reasonable default popup rules for a variety of buffers.
vc-gutter
- [✅️] git-gutter-fringe
hl-todo
- [❌️] hl-todo
workspaces
- [✅] persp-mode
- I added a couple of modifications to include special buffers from project to the enabled workspace at the time
evil
Module responsible for bringing Vim over to the party.
- [✅] evil
- There are some dependencies required by
evil
stated in their README page: - Evil requires any of the following for
C-r
- [✅] undo-fu
- However, Doom also uses undo-fu-session to save/restore undo history. I'm not interested in this.
- [❌] undo-fu-session
- There are some dependencies required by
- [⚠️] evil-args
- [⚠️] evil-easymotion
- [⚠️] evil-embrace
- [✅] evil-escape
- [✅️] evil-exchange
- I'm extremely happy I'm going through all of this! What a nice package!!!
- learn more about this here
- be aware that in Doom the keybinding is bound to
gx
instead ofcx
as in vim-exchange. Yeah, the way evil works... this is a gem!
- [⚠️] evil-indent-plus
- [⚠️] evil-lion
- [✅️] evil-nerd-commenter
- Comment code efficiently!
- [❌️] evil-numbers
- :/ I think I never had to increase/decrease numbers by unit before
- [⚠️] evil-snipe
- [✅️] evil-surround
- I use this plugin everytime! I'm not using smartparens to handle surrounding.
- Actually, I use
add surrounding
(yS<textobject>
) a lot but not the next ones:- change surrounding:
cs<old-textobject><new-textobject>
- delete surrounding:
ds<textobject>
- change surrounding:
- [⚠️] evil-textobj-anyblock
- [✅️] evil-traces
- It's useful to visualize the output of some commands before applying it
- I'm not so good at Ex commands in Vim, so I generally like visual hints that I'm not doing something wrong.
- [❌️️] evil-visualstar
- Didn't see any improvement in the behavior of plain
*
or#
- tbh, I think I'm not a power user of Visual mode so I don't see the benefit here.
- Didn't see any improvement in the behavior of plain
- [⚠️] exato
- [⚠️] evil-quick-diff
- [✅] evil-collection
file-templates
- [✅] yasnippet
multiple-cursors
- [⚠] evil-multiedit
- [⚠️️] evil-mc
- [⚠️️] multiple-cursors
snippets
- [✅] yasnippet
- [⚠️️] auto-yasnippet
- [⚠️️] doom-snippets
dired
- [❌] diredfl
- [✅️] dired-git-info
- This is nice specially because it comes disabled and I can toggle using
)
in Dired buffer - However, I'm still having double thoughts about its usefulness... I never needed this feature, but who knows now that I'm aware of it
- This is nice specially because it comes disabled and I can toggle using
- [❌] diff-hl
- [❌] fd-dired
- [❌] dired-rsync
electric
No external package! Small customization from Doom also.
vc
- [💠] browse-at-remote
- After removing the package, Doom didn't startup correctly.
-️️ [⚠️️] git-commit
- [✅] git-timemachine
- [⚠] git-modes
undo
These packages are required by evil
in order to enable evil-redo
(Ctrl-r
) properly.
- [✅] undo-fu
- Simple, stable linear undo with redo for Emacs.
- Changes compared to Emacs undo:
- Redo will not pass the initial undo action
- Redo winn not undo
- These constraints can be disabled by pressing
C-g
before undo or redo.
- Doom increases the undo-limit, I'd like to revert that to defaults. Look for the default values at
preferences/+doom.el
- [❌] undo-fu-session
eshell
- [⚠️️] eshell-z
- [⚠️️] eshell-did-you-mean
- [⚠️️] esh-help
- [⚠️️] shrink-path
- [⚠️️] eshell-up
- [☑️] eshell-syntax-highlighting
syntax
- [✅️] flycheck
- [⚠️] flycheck-popup-tip
lookup
- [✅️] dumb-jump
- [✅️] request
- For online lookup
magit
- [✅️] magit
- [❌️] magit-gitflow
- Oh, I'm glad I don't work following gitflow anymore
- [❌️] magit-todos
- [😎] code-review
- I'm the maintainer, so yeah! I should use it.
macos
- [❌] ns-auto-titlebar
- [❌] osx-trash
clojure
- [✅] clojure-mode
- [✅] clj-refactor
- [✅] cider
- reading its documentation always teaches me something new
- I could not make the fuzzy completion work with CIDER. The instructions from CIDER docs didn't work
- [✅] flycheck-clj-kondo
emacs-lisp
- [❌] macrostep
- [❌] overseer
- [❌] elisp-def
- [❌] elisp-demos
markdown
- [✅] markdown-mode
- [✅] edit-indirect
- [✅] evil-markdown
- Let's keep
evil-everywhere
motto!
- Let's keep
- [✅] grip
- Displays Github-flavored markdown in xwidget or browser
- [❌] markdown-toc
org
- [✅] org
- [✅] evil-org
- [❌] org-roam
- [✅] ox-hugo
- [✅] org-journal
- [⚠] org-contrib
- [❌] avy
- [❌] org-yt
-️ [⚠️️] ox-clip
- [⚠️️] orgit
- [⚠️️] toc-org
- [⚠️️] org-cliplink
- [💠] htmlize
plantuml
- [✅] plantuml-mode
- [✅] flycheck-plantuml
config
- [❌] avy
- [❌] drag-stuff
- [❌] link-hint
- [❌] expand-region
The little voice is getting louder...
Yeap, now it's time for the keybindings. Some modes add lots of bindigs with custom functions and whatnot. Let's start documenting a few obvious ones:
이제 키 바인딩을 살펴볼 차례입니다. 일부 모드는 사용자 정의 함수 등으로 많은 바인딩을 추가합니다. 몇 가지 눈에 띄는 것부터 문서화해 보겠습니다:
| keybinding | description | |------------|----------------------| | spc + ret | jump to bookmark | | spc + spc | find file in project | | spc + y | kill-ring history | | spc + ~ | toggle last popup |
Vim
알고 싶은 부분이 있다면?! 몰랐던 무엇인가?!
- [ ] ...
General
Vim is fundammentally built on command composability. Vim favors small, general-purpose commands that can be combined with objects to compose larger commands.
Vim은 기본적으로 명령 구성성을 기반으로 합니다. Vim은 객체와 결합하여 더 큰 명령을 구성할 수 있는 작고 범용적인 명령을 선호합니다.
- use the more general text objects (
iw
rather thanw
) - prefer
text objects
over motions when possible- words:
w
- sentences:
s
- paragraph:
p
- double quoted string:
"
- parenthesized block:
)
- indentation block:
i
- words:
- visual mode is a smell because it breaks repeatability
- don't use two sentences where one will do it
- to avoid using Esc we can press
C-[
orjk
in Doom - history of past searches:
q/
ctrl-^
will send you back to the previous buffer you were ingn
for the next occurrence of the last used search pattern- always be scrolling! don't use
hjkl
to move around the screen
Marks
[2023-06-15 Thu 15:46]
A mark allows to record the current cursor position, then later we can return to it. They have one non-trivial problem, you can't easily see them while working on your document.
*mark*를 사용하면 현재 커서 위치를 기록한 다음 나중에 해당 위치로 돌아갈 수 있습니다. 문서 작업 중에 쉽게 볼 수 없는 사소한 문제가 하나 있습니다.
- each file has available marks identified by lowercase letters from
a
toz
- global marks are identified by uppercase letters
- marks are motions, so you can use them with actions
Using marks
To jump to a mark enter an apostrophe '
or a backtick `
followed by the letter where the mark was set.
Using an apostrophe jumps to the beginning of the line holding the mark, while a backtick jumps to the line and column of the mark.
There are many ways to use marks, the following table summarize some of it:
| Command | description |
|---------|-------------------------------------------------------------|
| ]' | jump to next line with a lowercase mark |
| [' | jump to previous line with a lowercase mark |
| ]` | jump to next lowercase mark |
| [` | jump to previous lowercase mark |
| `` | after a movement, you can return to your previous location |
| ctrl-^ | send you back to the previous buffer that you were in |
| d`p | delete to mark p
|
| d'p | delete everything including the line mark p
is on |
| y`p | yank to mark |
| `' | jump back and forth between the last two jump destinations |
| `. | jump to the position of the last edit |
| '. | jump to the line of the last edit |
| `< | jump to the start of the last visual selection |
| `> | jump to the end of the last visual selection |
| '< | start of visual selection |
| >' | end of visual selection |
| '[ | start of last change or yank |
| '] | end of last change or yank |
| '. | position of where last change was made |
| '^ | position of cursor when last time Vim left insert-mode (gi) |
| '' | positon before last jump |
Example of
`` usage:
/while<Enter>
;; jump to the first match of while
Deleting Marks
You can delete marks with the `:delm` command. To delete marks ``a`, ``e`, and ``G`, you would type `:delm aeG`. You can delete all local marks with `:delm!`
Seeing Marks
Without plugins you can "see" your marks by running :marks
which shows you a quickfix window that list all your marks.
Resources
- Vim (14) Marks
- Marks - Vim works
Text Objects
[2023-06-15 Thu 15:47]
Vim provides text objects for the three building blocks of plaintext: words, sentences, and paragraphs. Vim's text objects provides an incredible level of precison, the key is to try to always edit by text objects.
Vim은 일반 텍스트의 세 가지 구성 요소인 단어, 문장, 단락에 대한 텍스트 개체를 제공합니다. Vim의 텍스트 개체는 놀라운 수준의 정밀도를 제공하며, 핵심은 항상 텍스트 개체로 편집하는 것입니다.
aw
- a word (includes surrounding white space)iw
- inner word (does not include surrounding white space)it
- xml/html tag (applies to everything in current xml/html tag)
This convention about the a
and i
is followed by all text objects.
as
- a sentenceis
- inner sentenceap
- a paragraphip
- inner paragraph
Programming language text objects
Vim provides several text objects based on common programming language constructs.
| Command | Description | |---------|-------------------------------| | a" | a double quoted string | | i" | inner double quoted string | | a) | a parenthesized block | | i) | inner parenthesized block | | i{ | inner nearest curly brackets | | ai | a indentation block | | ii | inner indentation |
Examples
This sentence has a hidden code block (function arg1 arg2)
gdii
will comment all indentation
References
- Vim text objects the definitive guide - Jared Carroll blog post
Motions
[2023-06-15 Thu 15:47]
These commands move the cursor position.
The motion commands can be used after an vim-operator
command, to have the comand operate on the text that was moved over.
| Commands | Description |
|-----------------|-------------------------------------------------------|
| I | start insert mode in the beg of a line |
| A | start insert mode in the end of a line |
| H | high |
| M | middle |
| L | low |
| zt | put the cursor positon to top |
| zz | put the cursor position to middle |
| zb | put the cursor position to bottom |
| Ctrl-U | scroll up half screen |
| Ctrl-B | scroll up full screen |
| Ctrl-Y | scroll up incrementally |
| Ctrl-D | scroll down half screen |
| Ctrl-F | scroll down full screen |
| Ctrl-E | scroll down incrementally |
| Ctrl-o / Ctrl-i | cycle through :jumps
|
| f/F and t/T | find characters |
| + | to go to the next line |
| ^ | goto the first non-blank character of the line |
| g_ | goto the first non-blank character of the line |
| % | goto the corresponding (, [, or { |
| * | goto the next occurrence of the word under cursor |
| # | goto the previous occurrence of the word under cursor |
| ] | next-* |
| [ | previous-* |
| [m | move to the beginning of the current method |
| ]m | move to the beginning of the next method |
After applying the operator the cursor is mostly left at the start of the text that was operated upon.
Exclusive vs Inclusive
Directly from :help exclusive
in Vim:
A character motion is either inclusive or exclusive. When inclusive, the start and the end position of the motion are included in the operation. When exclusive, the last character towards the end of the buffer is not included.
We can find out what word motions are inclusive or exclusive by reading :help word-motions
in Vim
| Command | Description | |---------|------------------| | w | exclusive motion | | W | exclusive motion | | e | inclusive motion | | E | inclusive motion | | b | exclusive motion | | B | exclusive motion | | ge | inclusive motion | | gE | inclusive motion |
Looking in retrospect and digging a little more into the motions help files in Vim seems like only e
is inclusive and all other motions are exclusive. Huge asterisk here because I've checked only the ones I use regularly.
Jumplist
[2023-06-15 Thu 15:48] From Vim's :help jumplist
:
Jumps are remembered in a jump list. With the Ctrl-o and Ctrl-i command you can go to cursor positions before olders jumps, and back again. Thus you can move up and down the list. There is a separate jump list for each window.
It's important to know what qualifies as a jump?
| Command | Description | |------------|----------------------------| | <n>G | jump to line <n> | | } | jump to next blank line | | { | jump to prev blank line | | [{ | jump to begin of block | | ]} | jump to end of block | | ) | jump to end of sentence | | ( | jump to begin of sentence | | ]] | jump to end of section | | [[ | jump to beg of section | | H | jump to top of window | | M | jump to middle of window | | L | jump to bottom of window | | % | jump to matching delimiter | | :tag ... | jump to specified tag | | Ctrl-t | jump to older tag | | Ctrl-] | jump to tag definition |
You can see all the jump list by typing :jumps
- Understanding Vim's jump list - Kade Killary blog post
Fold
[2023-06-15 Thu 16:08] !!! WARNING: I'M NOT USING FOLD FOR NOW!! I NEED TO GET USED TO OTHER THINGS FIRST!
The default fold method of Vim is manual
, so no folding occurs. There are several ways to add folds:
- zf{motion}: Create a fold based on motion
- visual selecton, zf: fold selection
| Commands | Description | |----------|-------------------------------------------| | zo | open fold | | zc | close fold | | zE | eliminate all folds in the current window | | za | toggle fold |
Brackets
[2023-06-15 Thu 16:08] Every programming language seems to make use of all brackets, incluiding curly and square. Clojure is by far no exception. =)
Movement and selection
Moving the cursor over a bracket and pressing %
will cause the cursor to jump to the corresponding bracket.
Resources
- Making Parenthesis/Brackets handling easier - Vim Wiki
Operators
[2023-06-15 Thu 16:08] The following operators are available:
| Command | Description | |---------|---------------------------------------| | c | change | | d | delete | | y | yank into register | | ~ | swap case | | g~ | swap case | | gu | make lowercase | | gU | make uppercase | | ! | filter through an external program | | = | filter through C-indenting | | == | indent the current line | | gq | text formatting | | > | shift right | | < | shift left | | zf | define a fold | | d]) | delete until the next close parens | | M-d | iedit select the current word forward | | M-D | iedit select the next word backward |
If the motion includes a count and the operator also had a count before it, then the two counts are multiplied. For example: "2d3w" deletes six words.
Insert Mode Shotcuts
When editing a file in Insert Mode, many shortcuts used elsewhere in Unix and other text editors are available.
| Command | Description | |--------------|------------------------------------------------| | Ctrl-w | delete the word before the cursor | | Ctrl-u | delete the current line | | Ctrl-[ | quits insert mode and goes back to Normal mode | | Ctrl-r {reg} | paste text from register | | Ctrl-n | invoke Vim's auto completion | | Ctrl-p | invoke Vim's auto completion |
The ex command g
The ex command g
is very useful for acting on lines that match a pattern. You can use it with the d
command to delete all lines that contain a particular pattern.
:g/pattern/d
References
Search
[2023-06-15 Thu 16:09] In normal mode you can search forwards by pressing /
then typing your search pattern. Type Gn
to jump to the first match, or GN
to jump to the last. Search backwards by pressing ?
then typing your search pattern.
cats and dogs dogs and cats people and cats
-
Search under cursor
You can search for the current word under the cursor by using the
*
and#
commands in normal mode. -
Reinsert substituted text
Using the
&
you can reinsert the text matched in a substitution run the following command to see the effect::%s/cats/"&"/g
-
Substitute capture groups
You can dictate capture groups using escaped brackets in a search. They can then be accessed in the replacement using escaped numbers.
:%s/\(\w\) and /\1 but not/g
-
History of past searches
You search for various keywords in your code. After a while you want to search for some of those keywords again but you don't remember them exactly. No worries. Just press
q/
and you'll open a small window at the bottom containing your searches. Navigate withjk
and press Enter to repeat the selected search. Or just close that window with:q
-
s
and type two characters to jump forward to the nearest match- if the things I want to jump to is fairly close to where the cursor is I'll use evil-snipe (s and S). If it's far away or in another window, I'll use Avy (gs SPC)
- if you want to jump to other matches use
;
and,
Search Pattern
| Pattern | Description | |---------|------------------------------------| | \< | represents the beginning of a word | | \> | represents the end of a word | | | |
-
Findind duplicate words:
\(\<\w\+\>\)\_s*\<\1\>
\<
word beginning\w
word character\+
one or more word characters\>
word end\_s*
any amount of whitespaces\1
uses the same pattern as the first group
-
Finding this or that
\|
to search for something or something else
-
Finding two words in either order
\&
separates alternates e.g..*red\&.*blue
will match either red or blue in any order.
Macros
[2023-06-15 Thu 16:09] You record your actions into a register and play those actions back.
- press
qa
to start recording your actions into registera
- perform some actions that you want repeated
- you press
@a
to playback the contents of regitera
- you could press
10@@
to repeat the playback for 10 times
G Commands
[2023-06-15 Thu 16:09] The global command :g
is very useful. [range]g/pattern/cmd
is the template for the g ex-command
Special list of G commands
| command | description | |----------------|----------------------------------------------------| | gf | open file under cursor | | g; | traverse forward through the change list | | g, | traverse backward through the change list | | gi | go back to last insert position | | ga | show char codes for char under cursor | | g& | repeat last :s on all lines (last replace command) | | gv | repeat last visual selection | | gh, gj, gk, gl | makes visual movements instead of logical | | :g!/pattern/d | delete all lines that do not match a pattern | | :g/^\s* | copy all lines matching a pattern to end of file | | :g/pattern/m$ | move all lines matching a pattern to end of file | | :g/pattern/y A | copy all lines matching a pattern to register 'a' |
Registers
[2023-06-15 Thu 16:09]
spc i r
to insert from evil-register
Antipatterns
[2023-06-15 Thu 16:09]
If you are pressing the same key more than twice, you're doing it wrong
- You should either prefix a command with the number of times you want to repeat
it or look for a shorter command which does the same thing (there always is).
Moving one line at a time
- use relative line numbers instead. Using relative line numbers will tell you how
many lines above and below the cursor the other lines are. Knowing that you can then use RELATIVE_NUMBER + j/k to jump straight to that line.
- I removed all line numbers from Doom.
- / to search for a word is usually faster than moving the cursor.
- to move up/down multiple lines I then use
CTRL+u
andCTRL+d
.
Moving sideways one character at a time
- use
f
to move to a particular character (forward) andt
to move to place right before a character (forward) - use
F
andT
to move backwards
Deleting text before inserting new text
Spending too much time in insert mode
Using / to search for the word under cursor
- Instead use * (to search forward) and # (to search backward)
Using macros for simple replacements
- Many people record a macro to change multiple lines when they could be using a
RegEx find and replace instead
- To invert a function's argument's order throughout all of a file's call, you could use:
- :%s/myfun(,)/myfun(\2,\1)/g
Daily Tricks - from Twitters
[2023-06-15 Thu 16:09] Find here a list of tips from Vim Daily Tips and Vim Tricks twitter profiles.
-
combine d, c, or y with
/
to operate on text up until apattern
match:d/foo
delete forward untillfoo
c/\d
change forward until the next number
-
navigate more efficiently by using jumps
ctrl-o
moves backwards through the jump listctrl-i
moves forwards through the jump list
-
removes lines matching a pattern with the
g
command:g/pattern/d
remove lines matching pattern:g!/pattern/d
remove lines that do NOT match
-
delete without overwriting your last yank
- use the black hole register `_`
"_daw
delete a word
- the 0 register will contain your most recent yank
"0p
put the yanked word before a delete
-
use
10@a
to play the macro saved in registera
10 times -
use
ea
to append to the end of the current word -
use
(
and)
to jump to the beginning and end of sentences -
scroll current line to
zt
scroll to topzb
scroll to bottomzz
scroll to center
-
Use
e
to move to the end of the next word, andge
to the end of the previous word -
Use
-
Use
gf
to jump to the file name under the cursor