:10,20y - copy contents from line 10 to 20
:%y+ - copy all content of a file on system clipboard
or
:%y
or
:%y
Press w to move one word at a time, that can be quite useful
Press b to move back one word at a time
dd - delete a line
5dd - delete or cut 5 line
y$ - copy or yank the whole file or end of line
p - paste the yanked line after cursor
P - paste the yanked line before cursor
1,$d - delete the whole text in a file
shift + d
or
D - delete that to end of line
Ctrl + r - redo
u - undo
U - restore (undo) last changed line
:set number - display number in file
:se nu - short form of set number
or set the above line to ~/.vimrc file
cat ~/.vimrc
set number
:se nu - short form of set number
or set the above line to ~/.vimrc file
cat ~/.vimrc
set number
:noh - Remove highlighting
:%s/old_text/new_text/g - Replace the old_text with new_text in the file
:%s/old_text/new_text/gc - Replace the old_text with new_text in the file with confirmation
5gg - go to line line 5
How to escape forward or backward slash in VIM editor:It is same as you use typically in linux.
search for all <br/> and replace with <cr\>
:%s/<br\/>/<cr\\>
Even you can use different delimiter @ OR #
:%s@<br/>@<cr\\>@
:%s#<br/>#<cr\\>#
Go to line number 50:Even you can use different delimiter @ OR #
:%s@<br/>@<cr\\>@
:%s#<br/>#<cr\\>#
:50
Replace /usr/local/bin with /user/home::%s/\/usr\/local\/bin/\/user\/home/g
Replace "https://hello.com@#" with hello::%s/https:\/\/hello.com@#/hello/g
To search forward a pattern:/pattern_name : to search forward
press n to see next occurrence
Open file with Line Number:press n to see next occurrence
vim +"set number" file-name.txt
Add the following line in ~/.vimrc file to autoindent in yaml fileautocmd FileType yaml setlocal et ts=2 ai sw=2 nu sts=0
syntax on
syntax on
I will keep adding to this blog. stay tuned!!
0 Comments