To create a new file just start a terminal emulator and type
$ vim
It will open a "window" inside the terminal window. Notice you can't write right away. VIM uses specific commands to start writing in different ways. To simply start writing press "i" (please that notice it's case sensitive). A label "INSERT" will appear in the bottom and everything you write will appear on the screen. To stop the "INSERT" mode, simply press esc. Here's a table of commands you can try to write differently:
a | Text after cursor |
A | Text at end of line |
i | Text before cursor |
I | Text at beginning of line |
a | New line + Insert |
a | New line(above) + Insert |
or to delete input text:
x | Erases character |
dnd | Delete n lines (dd to erase 1 line) |
D | Erase the rest of the linte |
and some other goodies:
yny | Copies n lines (yy for 1 line) |
p | Pastes lines (copied with yny or cut with dnd) |
u | Undo last change |
There are some useful navigation commands you can try as well. They are very useful for browsing through extensive code. The "/" [slash] character starts a search. If you type
/hello
the page will scroll until the next occurrence of "hello". If you want to go to the next after that, type
//
and so forward. Here's a list of some other useful navigation commands:
H | Top of screen |
M | Middle of screen |
L | Bottom of screen |
gg | First line |
G | Last line |
nG | Line n |
% | Finds the matching (,[,{ |
Now to save your file you must press ":" to open an inside command-line. There are a series of commands to be put here. I'll go through the basic:
:w
will write the modifications to the file
:wq
will write the modifications to the file and then exit
:q!
will exit without saving the file.
Besides that, I use three other commands that are very useful:
:set [no]nu
Turns the number of lines on and off
:set [no]ai
turns the indentation on and off
:set syntax=value
sets the syntax to value or if you want to turn it off, set it to value=off.
And that was it. Enjoy.
No comments:
Post a Comment