recent

Titulo

Vi Editor

What is your favorite text editor? The choice of text editors depends on the type of OS used for development. Edit plus and Vi are my choice for Windows and Linux.
What you should know about Vim/Vi? Vi is the most popular one and it is the ubiquitous text editor. It is highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X. Vim is rock stable and is continuously being developed to become even better. Among its features are:
  • persistent, multi-level undo tree
  • extensive plugin system
  • support for hundreds of programming languages and file formats.
  • powerful search and replace.
  • integrates with many tools.
Vi is a most popular text editor for Linux, UNIX and Mac. I was first introduced to Vi in school back in 2001. I loved it then and now. I have been using this for years, tried several other editors but nothing can replace Vi :%s/vi/nothing/g. Even though, I used it for years,  I do not claim to be a Vi expert but with this blog, I will show you just the minimum Vi commands that you need to get your work done. I promise rest of the vi commands are boring and you hardly use them.

It will not list all the 500+ commands that Vi offers. You don't need them all but always good to know that they are out. Below are the only Vi commands I know and I use for my projects and work. If I survived my decade long career using just these commands, you should too. 

INVOKING VI:  Invokes Vi and opens synonym.sql file if exist if not it creates one.
Vi synonym.sql

FILE: Creates or opens file
vi filename             #creates or open file
vi -R filename                  #opens existing file in read only mode
view filename           #opens existing file in read only mode

SAVE & EXIT: To save the changes or to quit without changing.
:w                                       #saves the change without closing file
:wq!                                    #saves the change and closes the file
:q                                       #exit without saving
:q!                                      #exit without saving

COMMAND MODE: This modes accepts vi command also exits  vi Input Mode on a file
ESC key

INPUT MODE: This mode lets your edit content to the file and also exits Command Mode. When Input Mode is activated, you will see Input Mode in big writings.
i

LINE NUMBER DISPLAY: Vi command to enable line numbers; shows the line number on a file you are working on. This is helpful to debug code and the setting last for a session only.
ESC key
:set number       #enables numbering.
:set nonumber   #disables numbering

LIST ALL COMMANDS: This displays all the settings/commands Vi offer.
<code> :set all</code>

LINE NUMBER NAVIGATION: Moving cursor to a specified line number.
:14                 #takes cursor to line number 14
:0                  #takes cursor to the first line
:$                   #takes cursor to the list line 

CURSOR NAVIGATION: Vi command to move cursor left, right, up, down using  h,j,k,l. This keys works like left, right, up and down arrow key.
h                    #moves cursor to Left (left arrow key)
l                    #opposite of h, moves cursor to Right (right arrow key0
j                    # moves cursor to Down (down arrow key)
k                    # moves cursor to Up (down arrow key)
0                    # beginning of line
$                    # end of line
w                    #beginning of word
b                    #reverse of w, back to previous word

SEARCH & REPLACE: Command to search a text or to replace text.
:/searchword                           #highlights all the search occurrences
:%s/searchword/replacewithkeyword/         #replaces one search occurrence
:%s/searchword/replacewithkeyword/g    #replaces all search occurrences

DELETE: Deletes a character or a single line
x                                  #deletes a single character
dd                                #deletes a single line

COPY & PASTE: Copies single line/word and paste it.
yy                                #copies single line of text
yw                                #copies single word of text
p                                  #pastes single line or text.

UNDO & REDO:
u                                  #undo changes
CTRL-R                          #reverse of undo

SEARCH HIGHLIGHTING: Vi command to enable/disable search highlighting.
:set hlsearch               #enables search highlighting
:set nhlsearch      #disables search highlighting

These commands will take your vi skills to master level, not the expert. More advanced commands are available on  http://www.vim.org.

Have a vi day folks!

Interested in working with me? I can be reached at pbaniya04[at]gmail.com for any questions, consulting opportunities or you may drop a line to say HELLO. Thank your again for visiting my blog and looking forward to serving you more.

Have a Database-ious Day!

No comments

Powered by Blogger.