{"id":238,"date":"2012-06-12T12:07:02","date_gmt":"2012-06-12T04:07:02","guid":{"rendered":"http:\/\/rmohan.com\/?p=238"},"modified":"2012-06-12T20:52:36","modified_gmt":"2012-06-12T12:52:36","slug":"vi-editior","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=238","title":{"rendered":"Vi Editior"},"content":{"rendered":"<p><strong>Vi Editior <\/strong><\/p>\n<p>How to copy data in VI editor<\/p>\n<p>vi first  edit source file<br \/>\nthen move your cursor to start of selection<br \/>\nma       mark current position with letter a<br \/>\nthen move your cursor to end of selection<br \/>\ny&#8217;a     yank to buffer x from current position to mark a<br \/>\n:e other  edit target file<br \/>\nmove cursor to where you want the data<br \/>\np       put from buffer x<\/p>\n<p>Copying a block of text from one file to another in Vi<br \/>\nDecember 29th, 2008 No comments<\/p>\n<p>To copy a block of text between files execute the commands:<br \/>\nCommand \tExplaination<br \/>\n1. \t\tEdit the file containing the text you want to copy.<br \/>\n2. \t\tGo to the top line to be copied.<br \/>\n3. \tma \tMark this line as mark \u201ca\u201d.<br \/>\n4. \t\tGo to the bottom line to be copied<br \/>\n5. \ty&#8217;a \tYank (y) the text from the current cursor location to the mark \u201ca\u201d (&#8216;a)<br \/>\n6. \t:split second-file \tOpen another window containing the second file. (This the file in which the text is to be inserted.)<br \/>\n7. \t\tGo to the line where the insert is to occur. The text will be place after this line.<br \/>\n8. \tp \tPut the text after the cursor.<\/p>\n<p>For Vi Editor<br \/>\nDo you like www.linuxnix.com ? Please consider supporting us by becoming a subscriber and get a Linux basics e-book for free.<br \/>\nunix_vi_editor<\/p>\n<p>VI editor is the default file editor in most of the Linux\/Nix machines. It is having great capabilities to edit a file with in few key strokes.<\/p>\n<p>Lets start with some general information and then move on to some good things what vi editor can do for you while editing a file.<br \/>\n1. Vi stands for visual.<br \/>\n2. Vi have its variants like vim which stands for Vi IMproved, VimX11 for gui and winvi for MS windows.<br \/>\n3. Vi is the most popular editor and next most popular editor is gedit.<br \/>\n4. Do you know there is a book on VI editor from orally which is of 600+ pages.<br \/>\n5. Some other editors which will do the work of editing files are neno, pico, gedit, emacs, joe, nedit, ed etc.<\/p>\n<p>Learning vi editor and remembering them is a very a easy task if you learn it in a systematic way.<br \/>\na. Modes of VI<br \/>\nb. Navigational commands<br \/>\nc. Editing commands.<br \/>\nd. Search and Replace<br \/>\ne. Save and quiting a file.<\/p>\n<p>a. Modes of VI :<br \/>\nVi have two mode of operation.<br \/>\n1. Command mode<br \/>\n2. Inserting mode<\/p>\n<p>Command mode :<br \/>\nVi editor begins in command mode, where cursor movement(navigation in the file) and editing occur. To enter in to command mode from Inserting mode press esc button.<\/p>\n<p>Inserting mode :<br \/>\nUsed for entering text, this is similar to notepad in Windows. To enter in to inserting mode you can use any of the following.<br \/>\ni or I => present line<br \/>\no => one line down the present line<br \/>\nO => one line above<\/p>\n<p>Note : All comments will work in command mode only.<\/p>\n<p>b. Navigational commands :<br \/>\n1. Character navigation k, h, l and j<br \/>\nh => To move one character left.<br \/>\nj => To move one line down.<br \/>\nk => To move one line up.<br \/>\nl => To move one character right.<\/p>\n<p>How to use above commands in clever way?<br \/>\nExamples :<br \/>\n6j => to move 6 lines down from the present courser.<br \/>\n7k => to move 7 lines above from the present courser.<\/p>\n<p>2. Word Navigation<br \/>\nw => word forward.<br \/>\ne =>word forward, but end of the word.<br \/>\nb => one word backward.<\/p>\n<p>Examples :<br \/>\n32w => To move 32 words forward<br \/>\n6b => To move 6 words back.<\/p>\n<p>3. Setting (nu) mbering to lines<br \/>\n:set nu<br \/>\nRemoving of (nonu)mbering to lines<br \/>\n:set nonu<\/p>\n<p>4. Moving paragraphs<br \/>\nmove one paragraph up => {{<br \/>\nmove one paragraph down => }}<\/p>\n<p>5. Moving page up\/down<br \/>\nFor up => ctrl+b<br \/>\nFor down => ctrl+f<\/p>\n<p>6. Moving start\/end of the file<br \/>\nStarting of the file(first line => [[<br \/>\nEnd of the file(last line) => ]]<\/p>\n<p>7. Going to any line :<br \/>\n:lineno<\/p>\n<p>Example :<br \/>\nIf we want to go to 56 line then type<br \/>\n:56<\/p>\n<p>c. Editing commands<\/p>\n<p>8. Replace one letter<br \/>\nReplace one letter => r<br \/>\nDelete one letter => x<\/p>\n<p>>9. Editing one word<br \/>\nEdit one word => cw<br \/>\nDelete one word => dw<\/p>\n<p>10. Editing one line<br \/>\nEditing a line from courser to the end of that line => d$<\/p>\n<p>11. Cutting<br \/>\ndeleting(cutting) one line => dd<\/p>\n<p>Examples :<br \/>\n2dd(deleting\/cutting two lines)<\/p>\n<p>12. Pasting<br \/>\nPasting a line below the courser => p<br \/>\nPasting a line above the courser => P<\/p>\n<p>13. Coping<br \/>\nCopying one line => yy<br \/>\nCopying n lines => nyy<\/p>\n<p>14. Special commands<br \/>\njoining lines => J<br \/>\nundoing things => u<br \/>\nrepeating previous command => .<\/p>\n<p>d. Search and replace<\/p>\n<p>15. Search for a term \/term<\/p>\n<p>Example : If you want to search for suresh then press \/suresh enter<br \/>\n\/suresh<br \/>\nMoving to next occurrence, press \u201cn\u201d with out quotes moving to previous occurrence, press \u201cN\u201d with out quotes.<\/p>\n<p>16. Searching and replacing a term(here separator is \/ )<br \/>\n:%s\/searchterm\/replaceterm\/g<br \/>\nchange default separator<br \/>\n:%s_\/home\/surya\/grade_\/home\/testing\/dest_g<\/p>\n<p>To search and replace particular term from given line to other given line.<br \/>\n:%s294,304\/sahana\/xyz\/g<\/p>\n<p>e)Save and quiting a file<br \/>\n:w => save the file<br \/>\n:q => quit the file<br \/>\n:wq => save and quit<br \/>\n:w! => force save the file<br \/>\n:q! => force quit with out save<br \/>\n:wq => save and quit forcefully<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vi Editior <\/p>\n<p>How to copy data in VI editor<\/p>\n<p>vi first edit source file then move your cursor to start of selection ma mark current position with letter a then move your cursor to end of selection y&#8217;a yank to buffer x from current position to mark a :e other edit target file move [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/238"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=238"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/238\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/238\/revisions\/242"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}