Before to start we have to see the learning curve have Vim.
This is not meant to demotivate you, is for know Vim is gonna be hard. And you have to love the challenge. At the start, you have to learn a lot and practice a lot. But once you get the hang of it, you can edit text without thinking about it. In flow
First press in your keyboard Ctrl + Alt + t
Now it’s time to install Vim if you are in ubuntu try this command
sudo apt install vim
if you don’t know you have vim put this in your terminal
vim --version
Have to appear you something like that:
If you see very much text is because you have it. After to confirm you have it let’s continue
Open vim just typing vim
in your terminal/console
Let’s start with the initial commands
Normally when you start to use Vim you see something like this, you don’t know what to do, search in google how to close vim and your frustrating, but to be honest vim no is too hard like others say.
Now let’s press i
Like you see is a Insert on the down, that’s mean you can write freely you want. Exist 3 modes in Vim, Visual mode
, Insert mode
and Normal Mode
. You pass to Normal mode
into -> Insert mode
.
If you wan’t to come back press esc
Now you know the basis in vim it’s time to move it in Normal Mode
if you are in Insert mode
press esc
and follow these:h
: move leftj
: downk
: upl
: right
If you want to save your file follow this table:
Command | Function |
---|---|
vim | Opens the specified file. If it doesn’t exist, it creates it |
:q | Closes the editor |
:w | Saves the changes |
/[busqueda] | Searches within the text |
dd | In normal mode, selects a line and deletes it |
You learned Moving 🗸 delete🗸, quit🗸 and save 🗹
I give you some tips, depend very much the utilities your gonna use vim for replace vscode, or edit content, use it like replace bash is in your choice and for what you like it. 👍
Record actions
The command q
can record what you do, e.g. 3w, for stop it press again q
is very useful if you wanna save a specific command you can reproduce it like @a
or any letter from a
to z
.
Move at the start and at the end of the file
The command gg
put you in the start of your file is very useful. And the command shift
+ g
put you in the end
Other movements
If you wanna move faster you can press w
or b
w
: move you in the first letter of a word in the next line ->b
: move you in the first letter of a word in the before line <-
See it like this w
is left and b
is right
You are starting so you can see it like this
Paste the last deleted or copied text.Normal mode
u
: Undo the last action. (ctrl + z)ctrl
+r
: Redo anything that was undo. (ctrl + shift + z)Saving and Quitting:
:wq
+ Enter: Save and quit.Searching and Replacing:
/
starts searching from your current cursor position and goes downward, moving toward the end of the document. It searches from the cursor position to the end of the file.?
starts searching from your current cursor position and goes upward, moving toward the beginning of the document. It searches from the cursor position to the beginning of the file.So, /
is used for forward searching (from the cursor towards the end of the document), while ?
is used for backward searching (from the cursor towards the beginning of the document). This allows you to search in both directions within your document, depending on your needs.
Copying and Pasting (Visual Mode):
v
: Enter Visual mode (for selecting text).y
: Yank (copy) the selected text.p
: Paste the copied text.If you want to practice more, there are some resources that can help you. For example, you can check out Vim script, Vim tutorial and Opensource. Remember, try to use Vim all the time, even for commands like sudo apt update
. You can do this in Vim by pressing :! sudo apt update
. You can also become root by typing :! su root`. Learning Vim is like acquiring another language if you want to become fluent, you need immersion yourself in it.