vim is a text editor to help us manipulate text faster ( you can handle everything with shortcuts. )
$vim test.txt
this command opens test.txt file if exists. Otherwise, it creates test.txt file in the current directory ( if you save and quit from vim :) )
There are 3 modes on vim
Modes | what it is doing | Key Shortcut |
---|---|---|
Normal Mode | Everything is shortcut | esc |
Insert Mode | for editing file, Insert mode is the same as normal text editing. | inNormal Mode press 'i' |
Visual Mode | For selecting and listing things. | inNormal Mode press 'v' |
Most searched thing :)
:wq -> write quit
:q! -> force quit without saveing
:w -> only write
ZZ -> same as :wq
ZQ -> same as :q!
Normal Mode: Everything is a shortcut.
Press i for insert mode.
a-> rightside
Write some text.
h,j,k,l -> For movement
w-> word
e->end
b-> back
$ -> end
0 -> beginning
GG -> move cursor to top
g -> move cursor to bottom
c-> change
d->delete
y->yank
p->paste
x->char delete
:d3w
I -> enter insert mode in beginning of line
A -> enter insert mode at the end of line
o -> insert mode with new bottom-line
O -> insert mode with new upper-line
. -> repeats the last thing you do.
"this is sample string"
:ci"
:ca"
:di"
:da"
p -> Paragraph
also show tag
t -> ( cit ) changes inside tag like div tag etc
u for undo
ctrl+r for redo
sample1: git commit -m "JiraId:4321 message: this is sample message. tag:VimEditor,VimCourse"
sample2: create new alias.
cf.
df.
y -> yank
p -> paste
gUw -> makes the word all upper case gU2w -> makes the 2 word all upper case guw -> makes the word all lower case
vim -c "normal! @p" filename -c wq
this command opens the filename then in normal mode running the @p macro ( you can change here ) then quit the file with wq
vim -c "normal! A this is first line ending" filename
this script adding the " this is first line ending" text to end of the first line