In this video you will learn about the vi/VIM editor. If some of the commands don't work just let me know. Since i can't post the commands i'll be posting th. Vi starts in command mode. The positioning commands operate only while vi is in command mode. You switch vi to input mode by entering any one of several vi input com-mands. (See next section.) Once in input mode, any charac-ter you type is taken to be text and is added to the file. You cannot execute any commands until you exit input mode. It is true that command key. You can see it by:help vim+terminal.It only works in MacVim.See here. The best shot for your intention is to map the combination as hex code, sending to terminal. Otherwise, vim doesn't recognize any commands (naturally, since each Chinese character involves pressing a sequence of multiple keys). I see that vim comes with certain input-method-aware features ( e.g.,:h 'imactivatekey' ), but they appear to be compatible only with X11 + GTK.
VIM Editor Commands
Vim is an editor to create or edit a text file.
There are two modes in vim. One is the command mode and another is the insert mode.
In the command mode, user can move around the file, delete text, etc.
In the insert mode, user can insert text.
Changing mode from one to another
From command mode to insert mode type a/A/i/I/o/O ( see details below)
From insert mode to command mode type Esc (escape key)
Some useful commands for VIM
Text Entry Commands (Used to start text entry)
a Append text following current cursor position
A Append text to the end of current line
i Insert text before the current cursor position
I Insert text at the beginning of the cursor line
o Open up a new line following the current line and add text there
O Open up a new line in front of the current line and add text there
The following commands are used only in the commands mode.
Cursor Movement Commands
h Moves the cursor one character to the left
l Moves the cursor one character to the right
k Moves the cursor up one line
j Moves the cursor down one line
nG or :n Cursor goes to the specified (n) line
(ex. 10G goes to line 10)
^F (CTRl F) Forward screenful
^B Backward screenful
^f One page forward
^b One page backward
^U Up half screenful
^D Down half screenful
$ Move cursor to the end of current line
0 (zero) Move cursor to the beginning of current line
w Forward one word
b Backward one word
Exit Commands
:wq Write file to disk and quit the editor
:q! Quit (no warning)
:q Quit (a warning is printed if a modified file has not been saved)
ZZ Save workspace and quit the editor (same as :wq)
: 10,25 w temp
write lines 10 through 25 into file named temp. Of course, other line
numbers can be used. (Use :f to find out the line numbers you want.
Text Deletion Commands
x Delete character
dw Delete word from cursor on
db Delete word backward
dd Delete line
d$ Delete to end of line
d^ (d caret, not CTRL d) Delete to beginning of line
Yank (has most of the options of delete)-- VI's copy commmand
yy yank current line
y$ yank to end of current line from cursor
yw yank from cursor to end of current word
5yy yank, for example, 5 lines
Paste (used after delete or yank to recover lines.)
p paste below cursor
P paste above cursor
'2p paste from buffer 2 (there are 9)
u Undo last change
U Restore line
J Join next line down to the end of the current line
File Manipulation Commands
:w Write workspace to original file
:w file Write workspace to named file
Vi Commands Mac
:e file Start editing a new file
:r file Read contents of a file to the workspace
To create a page break, while in the insert mode, press the CTRL key
And l. ^L will appear in your text and will cause the printer to start
A new page.
Other Useful Commands
Most commands can be repeated n times by typing a number, n, before
the command. For example 10dd means delete 10 lines.
. Repeat last command
cw Change current word to a new word
r Replace one character at the cursor position
R Begin overstrike or replace mode – use ESC key to exit
:/ pattern Search forward for the pattern
:? pattern Search backward for the pattern
n (used after either of the 2 search commands above to
continue to find next occurrence of the pattern.
:g/pat1/s//pat2/g replace every occurrence of pattern1 (pat1) with
pat2
Example :g/tIO/s//Ada.Text_IO/g
This will find and replace tIO by Ada.text_IO everywhere in the file.
:g/a/s// /g replace the letter a, by blank
:g/a/s///g replace a by nothing
note: Even this command be undone by u
Examples
Opening a New File
Step 1 typevim filename(create a file named filename)
Step 2 typei ( switch to insert mode)
Step 3 enter text (enter your Ada program)
Step 4 hitEsc key(switch back to command mode)
Step 5 type:wq (write file and exit vim)
Editing the Existing File
Step 1 typevim filename(edit the existing file named filename)
Step 2 move around the file using h/j/k/l key or any appropriate command
h Moves the cursor one character to the left
l Moves the cursor one character to the right
Vi Commands Mac Os
k Moves the cursor up one line
j Moves the cursor down one line
nG or :n Cursor goes to the specified (n) line
(ex. 10G goes to line 10)
Step 3 edit required text (replace or delete or insert)
Step 4 hit Esc key (exit from insert mode if you insert or replace text)
Vim Text Editor Mac
Step 5 type:wq
vi is one of the most commonly used editor program and included by default with every UNIX and linux system. vi basically operates in 3 modes, namely :
- vi mode – the mode vi starts in
- command mode – you can be in command mode from the vi mode by pressing the key colon (“:”)
- input mode – in this mode user starts the actual editing of the text
Below are some of the most commonly used vi commands in all 3 modes of operation.
vi mode commands
Command | Action |
---|---|
k | Move one line upwards |
l | Move one character to the right |
h | Move one character to the left |
w | Move one word to the right |
W | Move one word to the right past punctuation |
b | Move one word to the left |
B | Move one word to the left past punctuation |
e | Move to the end of the current word |
1G | Move to the beginning of the file |
H | Move to the top of the current screen |
M | Move to the middle of the current screen |
L | Move to the bottom of the current screen |
Ctrl-G | Move to the last line in the file |
Ctrl-F | Move one screen towards the end of the file |
Ctrl-D | Move 1/2 screen towards the end of the file |
Ctrl-B | Move one screen towards the beginning of the file |
Ctrl-U | Move 1/2 screen towards the beginning of the file |
Ctrl-L | Refresh the screen |
5G | Move to line 5 of the file (5 can be any line number) |
/string | Find text string forward |
?string | Find text string backward |
n | Find forward next string instance after a string search |
N | Find backward next string instance after a string search |
ZZ | Save the file exit vi |
x | Delete the character at the cursor |
X | Delete the character behind the cursor |
dd | Delete the line the cursor is on |
10dd | Delete the 10 lines following the cursor |
yy | Yank the current line |
p | Put the yanked line below the current line |
P | Put the yanked line above the current line |
Command mode commands
Command | Action |
---|---|
:g/X/s//x/g | Global Search and replace (X=search object x=replace object) |
:r file | Import a file into the current file |
:34 r file | Import a file into the current file after line 34 |
:w | Write out the file to save changes |
:w file | Write the file to named file |
:wq | Save the file exit vi |
:w! | Force save the file |
:q! | Quit vi but don’t save changes |
How To Use Vim
Input mode commands
Command | Action |
---|---|
a | Insert characters to the right of the cursor |
A | Append characters to the current line |
i | Insert characters to the left of cursor |
I | Insert characters at the beginning of the current line |
o | Add a new line after current line |
O | Insert a new line above the current line |