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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
---
category: tool
tool: vim
lang = de-de
contributors:
- ["RadhikaG", "https://github.com/RadhikaG"]
translators:
- ["caminsha", "https://github.com/caminsha"]
filename: LearnVim-de.txt
---
[Vim](http://www.vim.org)
(Vi IMproved) ist ein Klon von vi, dem bekannten Editor für Unix. Es ist ein
Texteditor, welcher mit Fokus auf Geschwindigkeit und Prouktivität entwickelt
wurde.
Vim hat viele Keybindings für ein schnelles navigieren und schnelles bearbeiten
einer Datei.
## Grundlagen, um in Vim zu navigieren
```
vim <filename> # Öffne <filename> in Vim
:help <topic> # Open up built-in help docs about <topic> if any exists
:q # Schliesse vim
:w # Speichere diese Datei
:wq # Speichere diese Datei und schliesse vim
ZZ # Speichere diese Datei und schliesse vim
:q! # Schliesse vim ohne die Datei zu speichern
# ! *zwingt* die Ausführung von :q,
# daher wird die Datei nicht gespeichert.
ZQ # Beende vim ohne die Datei zu speichern
:x # Speichere die Datei und beende vim
# Dies ist eine kürzere Version von :wq
u # Änderung rückgängig machen
CTRL+R # Änderung wiederherstellen
h # Den Cursor um ein Zeichen nach links bewegen
j # Den Cursor eine Zeile nach unten bewegen
k # Den Cursor eine Zeile nach oben bewegen
l # Den Cursor um ein Zeichen nach rechts bewegen
Ctrl+B # Gehe eine Bildschirmanzeige zurück
Ctrl+F # Gehe eine Bildschirmanzeige vorwärts
Ctrl+D # Gehe eine halbe Bildschirmanzeige vorwärts
Ctrl+U # Gehe eine halbe Bildschirmanzeige zurück
# Navigieren innerhalb einer Zeile
0 # Navigiere zum Anfang der Zeile
$ # Navigiere zum Ende der Zeile
^ # Navigiere zum ersten Zeichen, welchen kein Leerzeichen ist
# Im Text suchen
/word # Hebt alle Ergebnisse nach dem Cursor hervor
?word # Hebt alle Ergebnisse vor dem Cursor hervor
n # Bewegt den Cursor zum nächsten Ergebnis nach der Suche
N # Bewegt den Cursor zum vorherigen Ergebnis der Suche
:%s/foo/bar/g # Ersetze "foo" durch "bar" in allen Zeilen
:s/foo/bar/g # Ersetze "foo" durch "bar" in der aktuellen Zeile
:%s/\n/\r/g # Replace new line characters with new line characters
# Jumping to characters
f<character> # Jump forward and land on <character>
t<character> # Jump forward and land right before <character>
# For example,
f< # Jump forward and land on <
t< # Jump forward and land right before <
# Moving by word
w # Move forward by one word
b # Move back by one word
e # Move to end of current word
# Other characters for moving around
gg # Go to the top of the file
G # Go to the bottom of the file
:NUM # Go to line number NUM (NUM is any number)
H # Move to the top of the screen
M # Move to the middle of the screen
L # Move to the bottom of the screen
```
## Help docs:
Vim has built in help documentation that can accessed with `:help <topic>`.
For example `:help navigation` will pull up documentation about how to navigate
your workspace!
`:help` can also be used without an option. This will bring up a default help dialog
that aims to make getting started with vim more approachable!
## Modes:
Vim is based on the concept on **modes**.
- Command Mode - vim starts up in this mode, used to navigate and write commands
- Insert Mode - used to make changes in your file
- Visual Mode - used to highlight text and do operations to them
- Ex Mode - used to drop down to the bottom with the ':' prompt to enter commands
```
i # Puts vim into insert mode, before the cursor position
a # Puts vim into insert mode, after the cursor position
v # Puts vim into visual mode
: # Puts vim into ex mode
<esc> # 'Escapes' from whichever mode you're in, into Command mode
# Copying and pasting text
y # Yank whatever is selected
yy # Yank the current line
d # Delete whatever is selected
dd # Delete the current line
p # Paste the copied text after the current cursor position
P # Paste the copied text before the current cursor position
x # Deleting character under current cursor position
```
## The 'Grammar' of vim
Vim can be thought of as a set of commands in a
'Verb-Modifier-Noun' format, where:
- Verb - your action
- Modifier - how you're doing your action
- Noun - the object on which your action acts on
A few important examples of 'Verbs', 'Modifiers', and 'Nouns':
```
# 'Verbs'
d # Delete
c # Change
y # Yank (copy)
v # Visually select
# 'Modifiers'
i # Inside
a # Around
NUM # Number (NUM is any number)
f # Searches for something and lands on it
t # Searches for something and stops before it
/ # Finds a string from cursor onwards
? # Finds a string before cursor
# 'Nouns'
w # Word
s # Sentence
p # Paragraph
b # Block
# Sample 'sentences' or commands
d2w # Delete 2 words
cis # Change inside sentence
yip # Yank inside paragraph (copy the para you're in)
ct< # Change to open bracket
# Change the text from where you are to the next open bracket
d$ # Delete till end of line
```
## Some shortcuts and tricks
<!--TODO: Add more!-->
```
> # Indent selection by one block
< # Dedent selection by one block
:earlier 15m # Reverts the document back to how it was 15 minutes ago
:later 15m # Reverse above command
ddp # Swap position of consecutive lines, dd then p
. # Repeat previous action
:w !sudo tee % # Save the current file as root
:set syntax=c # Set syntax highlighting to 'c'
:sort # Sort all lines
:sort! # Sort all lines in reverse
:sort u # Sort all lines and remove duplicates
~ # Toggle letter case of selected text
u # Selected text to lower case
U # Selected text to upper case
# Fold text
zf # Create fold from selected text
zo # Open current fold
zc # Close current fold
zR # Open all folds
zM # Close all folds
```
## Macros
Macros are basically recordable actions.
When you start recording a macro, it records **every** action and command
you use, until you stop recording. On invoking a macro, it applies the exact
same sequence of actions and commands again on the text selection.
```
qa # Start recording a macro named 'a'
q # Stop recording
@a # Play back the macro
```
### Configuring ~/.vimrc
The .vimrc file can be used to configure Vim on startup.
Here's a sample ~/.vimrc file:
```
" Example ~/.vimrc
" 2015.10
" Required for vim to be iMproved
set nocompatible
" Determines filetype from name to allow intelligent auto-indenting, etc.
filetype indent plugin on
" Enable syntax highlighting
syntax on
" Better command-line completion
set wildmenu
" Use case insensitive search except when using capital letters
set ignorecase
set smartcase
" When opening a new line and no file-specific indenting is enabled,
" keep same indent as the line you're currently on
set autoindent
" Display line numbers on the left
set number
" Indentation options, change according to personal preference
" Number of visual spaces per TAB
set tabstop=4
" Number of spaces in TAB when editing
set softtabstop=4
" Number of spaces indented when reindent operations (>> and <<) are used
set shiftwidth=4
" Convert TABs to spaces
set expandtab
" Enable intelligent tabbing and spacing for indentation and alignment
set smarttab
```
### References
[Vim | Home](http://www.vim.org/index.php)
`$ vimtutor`
[A vim Tutorial and Primer](https://danielmiessler.com/study/vim/)
[What are the dark corners of Vim your mom never told you about? (Stack Overflow thread)](http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about)
[Arch Linux Wiki](https://wiki.archlinux.org/index.php/Vim)
|