generated from allisonhorst/meds-distill-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathvim.qmd
177 lines (123 loc) · 4.55 KB
/
vim.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
title: "Vim, the editor"
---
# Other text editors
## Your typical editor works like this...
* When you type almost any key, the corresponding character (letter,
number, symbol, or whitespace) appears at the cursor
* Certain special keys do special operations (control, alt, command,
super)
* For a GUI app, you can/must click menus for other functionality
# Vim is different
## Vim has _modes_
Normal
~ for almost everything except typing!
Insert
~ for typing
Visual
~ for highlighting a region to operate on
~ (and others you don't need to know about)
# The keyboard is your friend
![](img/vi-vim-cheat-sheet.gif)
# For the impatient
- Start vim in terminal: `$ vim test.txt`
- Press `i` to enter insert mode
- Type to your heart's content
- When you're done, hit `Esc` to leave insert mode
- Then type `:w` to save your document
- Then type `:q` to quit
- if you have unsaved changes, vim will complain
- to save, see previous, or do `:wq` in one step
- to discard changes and quit, do `:q!`
# Normal mode
### Now that you've seen that you _can_ actually type in vim, let's learn about the magic of Normal mode!
# Moving around ("motions")
**Stepping**
- by line: up `k`, down `j`
- by character: forward `l`, backward `h`
- by word: forward `w`, backward `b`
- by sentence: forward `)`, backward `(`
- by paragraph: forward `}`, backward `{`
# Moving around ("motions")
**Jumping**
- to start/end of line: `0/$`
- to first/last line of file: `gg/G`
- to a character on current line: `f/F{char}`
- to identical word: `*/#`
- to line number: `:{#}` or `{#}G`
- to top, middle, or bottom of screen: `{HML}`
# Insert
- starting right where you are: `i`
- starting at the next character -- `a`
- starting at the end of the current line -- `A`
- starting at the beginning of the line -- `I`
- starting on the next line -- `o`
- starting on the previous line -- `O`
- enter 'replace mode' right where you are -- `R`
- replace current character with one other character -- `r{char}`
- delete current character, then enter insert mode -- `s`
- delete current line, then enter insert mode -- `S`
# Delete (really, this is "cut")
- delete character under cursor: `x`
- delete character before cursor: `X`
- delete to end of line: `D`
- delete entire line: `dd`
- delete # lines: `d#d`
- delete over some motion: `d{motion}`
- use backspace in insert mode (like every other editor)
# Copy and paste
- copy ("yank") -- `y{motion}`
- copy ("yank") --
- paste after cursor -- `p`
- paste before cursor -- `P`
# Search and replace
- we already saw some of this with jumping
- search for arbitrary expression -- `/{expression}`
- search and replace
- `:s/foo/bar/`
- `:s/foo/bar/g`
- `:%s/foo/bar/g`
# Do-overs!
- undo change: `u`
- repeat last change: `.`
- redo last undone change: `Ctrl-r`
# Extras
- toggle case -- ~
# Saving and quitting
- save and quit: `ZZ` (or `:wq)`
- save and keep editing: `:w`
- quit without saving: `:q`
- *really* quit without saving: `:q!`
# Tabs
- open another file in new tab: `:tabe <file>`
- change tabs: forward `gt`, backward `gT`
# Basic editing
![http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html](img/vi-vim-tutorial-1.gif)
# Operators and repetition
![http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html](img/vi-vim-tutorial-2.gif)
# Yank & paste
![http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html](img/vi-vim-tutorial-3.gif)
# Searching
![http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html](img/vi-vim-tutorial-4.gif
)
# Marks & macros
![http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html](img/vi-vim-tutorial-5.gif)
# Various motions
![http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html](img/vi-vim-tutorial-6.gif)
# Various commands
![http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html](img/vi-vim-tutorial-7.gif)
# Places to learn
* The [pictorial cheatsheets](
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html)
used in this slide
- [Color PDF of all 8 diagrams](
http://www.glump.net/_media/howto/vi-vim-cheat-sheet-and-tutorial.pdf)
* A nice [introduction with some clear prose](
http://jmcpherson.org/editing.html)
* A popular portal to [the rest of the vim universe](
http://thomer.com/vi/vi.html)
* A bit heavy-handed, but if you really like learning by
[watching over someone's shoulder](
http://www.linuxconfig.org/Vim_Tutorial)...
* Lastly, if you just want to learn [how to start *and* quit vim all in
the first page of tips]( http://www.jerrywang.net/vi/)