-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnote_Vi_Editor.txt
111 lines (87 loc) · 5.41 KB
/
note_Vi_Editor.txt
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
### Vi Editor Tutorial
Vi is a powerful text editor available on most Unix-like systems. It's a modal editor with two main modes: command mode and insert mode.
In command mode, you can navigate, edit, and perform various operations on text. In insert mode, you can enter text.
#### Using the ESC Key
To exit from insert mode to command mode, simply press the `ESC` key. This will allow you to execute command mode commands such as navigation, editing, saving, and searching.
If you're in visual mode and want to return to command mode, pressing `ESC` will also achieve that.
#### Navigation
| Command | Description |
|------------------|-------------------------------------------|
| `h` or `←` | Move cursor left |
| `j` or `↓` | Move cursor down |
| `k` or `↑` | Move cursor up |
| `l` or `→` | Move cursor right |
| `0` | Move to the beginning of the line |
| `$` | Move to the end of the line |
| `gg` | Move to the beginning of the file |
| `G` | Move to the end of the file |
| `w` | Move forward one word |
| `b` | Move backward one word |
| `Ctrl + f` | Move forward one page |
| `Ctrl + b` | Move backward one page |
To return to command mode: Press `ESC`.
#### Editing
| Command | Description |
|------------------|-------------------------------------------|
| `i` | Switch to insert mode (before cursor) |
| `I` | Switch to insert mode (beginning of line) |
| `a` | Switch to insert mode (after cursor) |
| `A` | Switch to insert mode (end of line) |
| `o` | Open a new line below and switch to insert mode |
| `O` | Open a new line above and switch to insert mode |
| `x` | Delete character under cursor |
| `dd` | Delete current line |
| `yy` | Yank (copy) current line |
| `p` | Paste yanked or deleted text after cursor |
| `P` | Paste yanked or deleted text before cursor|
To return to command mode: Press `ESC`.
#### Saving and Exiting
| Command | Description |
|------------------|-------------------------------------------|
| `:w` | Save changes |
| `:wq` or `:x` | Save changes and exit (write and quit) |
| `:q` | Quit (exit) |
| `:q!` | Quit without saving changes (force quit) |
To return to command mode: Press `ESC`.
#### Search and Replace
| Command | Description |
|------------------|-------------------------------------------|
| `/pattern` | Search forward for a pattern |
| `?pattern` | Search backward for a pattern |
| `n` | Move to the next occurrence of the search pattern |
| `N` | Move to the previous occurrence of the search pattern |
| `:s/pattern/replacement` | Replace pattern with replacement (current line) |
| `:%s/pattern/replacement/g` | Replace pattern with replacement (entire file) |
To return to command mode: Press `ESC`.
#### Visual Mode
| Command | Description |
|------------------|-------------------------------------------|
| `v` | Enter visual mode (select text) |
| `V` | Enter visual line mode (select lines) |
| `Ctrl + v` | Enter visual block mode (select blocks) |
To return to command mode: Press `ESC`.
#### File Management
| Command | Description |
|------------------|-------------------------------------------|
| `:e filename` | Open a file for editing |
| `:w filename` | Save file with a new name |
| `:saveas filename` | Save file with a new name |
| `:r filename` | Import contents of filename |
| `:x` | Save changes and exit (write and quit) |
| `:q` | Quit (exit) |
| `:q!` | Quit without saving changes (force quit) |
| `:wq` or `ZZ` | Save changes and exit (write and quit) |
| `:x!` or `ZQ` | Save changes and exit (write and quit, even if file is read-only) |
| `:%d` | Empty the entire file |
| `u` | Undo last change |
| `Ctrl + r` | Redo last undone change |
| `.` | Repeat last command |
| `:set number` | Enable line numbering |
| `:set nonumber` | Disable line numbering |
| `:help` | Open Vi editor help |
| `:clear` or `Ctrl + l` | Clear the screen (useful for refreshing the terminal) |
To return to command mode: Press `ESC`.
---
This Vi editor tutorial covers basic navigation, editing, saving, searching, file management, and visual mode commands. Practice using these commands to become proficient with Vi.
If there is an error on line # 26:
vi +26 /etc/ssh/sshd_config