Gvim Commands
Gvim Commands
:wq - to exit from gvim after saving the file which you are in already
:w - saves the file which you are in but does not exit
mkdir dir name - Creates a new directory with the dir name
rmdir dir name - Removes a directory with the dir name mentioned if the directory is empty
rm -rf dir name - Removes a directory with the dir name irrespective whether there are files
in the directory or not and also with the same command we can also remove files in a directory with
their respective names
ls –l - displays the contents in the directory including time of the creation and last
visited
ls –lt - Displays the contents in the directory in the time wise (latest – earliest)
ls -ltr - Displays the contents in the directory in reverse order (earliest – latest)
mv -r - moves the files on one dir to another and removes the old dir
:%s/old/new/g - replace old letter with new letter through out the file
:%s/old/new/gc - replaces old letter with new letter through out the file with conformations
:w newfilename - when you are in a file and if you want to create a new file with different
name with the same contents you can use this command
wc -l file name - gives you the number of lines in a file with opening the file
fzsbuvanesh@gmail.com
grep
grep “word search” filename - Searches and displays for the word in the given file name
grep -w “word search” filename - Searches and displays for only that word in the given file name
grep -wi “ word search” filename - Searches and displays for the word if it has any lower
case or upper case words in the file name
grep -win “word search” filename - displays the numbers of the lines in which the word is
there
grep -win -B (number of lines) “word search” filename - Displays the number of lines required
before the searched word line
grep -win -A (number of lines) “word search” filename - Displays the number of lines required
after the searched word line
grep -win -C (number of lines) “ word search” filename - Displays the number of lines required
after and before the searched word line
grep -win “word search” ./* - if you want to search in the complete
directory and displays the result and does not searches in sub directory
grep -winr “word search” . - searches and displays the result even in
the sub directory as well
grep -wirl “word search” - searches and displays the files name in
which the word is matching
grep -wirc “word search” - Displays the number of times the word is
matching in each file
Regular Expression :
\d - Digit (0-9)
\b - Word Boundary
\B - Not a word boundary
^ - Beginning of a string
$ - End of a string
| - Either or
() - Group
Quantifiers:
*- - 0 or more
+ - 1 or more
? - 0 or one
{3} - Exact number
{3,4} - Range of Numbers (Minimum, Maximum)
File Handling:
Here, filename is string literal, which you will use to name your file
and accessMode can have one of the following values −
1 r
Opens an existing text file for reading purpose and the file must exist. This is the
default mode used when no access Mode is specified.
2 w
Opens a text file for writing, if it does not exist, then a new file is created else
existing file is truncated.
3 a
Opens a text file for writing in appending mode and file must exist. Here, your
program will start appending content in the existing file content.
4 r+
Opens a text file for reading and writing both. File must exist already.
5 w+
Opens a text file for reading and writing both. It first truncate the file to zero
length if it exists otherwise create the file if it does not exist.
6 a+
Opens a text file for reading and writing both. It creates the file if it does not
exist. The reading will start from the beginning, but writing can only be
appended.