{"id":700,"date":"2018-08-07T12:47:10","date_gmt":"2018-08-07T11:47:10","guid":{"rendered":"https:\/\/portal.supercomputing.wales\/?page_id=700"},"modified":"2018-08-07T12:54:07","modified_gmt":"2018-08-07T11:54:07","slug":"using-vi","status":"publish","type":"page","link":"https:\/\/portal.supercomputing.wales\/index.php\/using-vi\/","title":{"rendered":"Using Vi"},"content":{"rendered":"<h3>What is Vi?<\/h3>\n<div>Vi (pronounced vee-eye) is a text editor available on Super Computing Wales and virtually all Linux and Unix based computers. It was originally developed by Bill Joy in 1976 while he was at the University of California, Berkeley. Vi was designed to run on remote terminals over very slow connections and is known as the &#8220;visual editor&#8221;. Vi is part of the Linux standard base so you can guarantee that it will be installed on other Linux systems you may have access to.<\/div>\n<p>&nbsp;<\/p>\n<h3>Using Vi<\/h3>\n<div>To use Vi on Super Computing Wales you must logon to a head node such as hawklogin.cf.ac.uk. You can only use it in terminal mode. To logon to Super Computing Wales you can use PuTTY. Please read the documentation before installing, and note that you can download PuTTY for free and install it on your computer.<\/div>\n<p>&nbsp;<\/p>\n<h3>Getting Started<\/h3>\n<div>To begin editing a new file type &#8220;vi&#8221; at the command prompt<\/div>\n<div>Then type &#8220;i&#8221; to change to insert mode and begin typing<\/div>\n<div>Then press the &lt;Esc&gt; key when you are done typing<\/div>\n<div>Then type &#8220;:w path\/to\/file&#8221; and hit enter to save the file<\/div>\n<div>Then type &#8220;:q&#8221; to quit vi<\/div>\n<p>&nbsp;<\/p>\n<h3>Starting Vi<\/h3>\n<div>\n<table id=\"tablepress-16\" class=\"tablepress tablepress-id-16\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Command<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">vi<\/td><td class=\"column-2\">run vi<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">vi myfile.txt<\/td><td class=\"column-2\">run vi and open myfile.txt<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">vim<\/td><td class=\"column-2\">run vim<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">vim \/home\/user\/myfile.txt<\/td><td class=\"column-2\">run vim and open \/home\/user\/myfile.txt<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-16 from cache --><\/div>\n<div><\/div>\n<h3>Leaving Vi<\/h3>\n\n<table id=\"tablepress-17\" class=\"tablepress tablepress-id-17\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Command<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">ZZ<\/td><td class=\"column-2\">quit vi and write current file<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">:q<\/td><td class=\"column-2\">quit vi<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">:wq<\/td><td class=\"column-2\">write current file and quit<br \/>\n<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">:q!<\/td><td class=\"column-2\">quit vi and do not write current file<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-17 from cache -->\n<p>&nbsp;<\/p>\n<h3>File Operations<\/h3>\n\n<table id=\"tablepress-18\" class=\"tablepress tablepress-id-18\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Command<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">:e \/home\/user\/myfile.txt<\/td><td class=\"column-2\">edit myfile.txt (tab completion works)<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">:w \/home\/user\/myfile.txt<br \/>\n<br \/>\n<\/td><td class=\"column-2\">write myfile.txt (tab completion works)<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">:w<\/td><td class=\"column-2\">write open file<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-18 from cache -->\n<p>&nbsp;<\/p>\n<h3>Modes<\/h3>\n\n<table id=\"tablepress-19\" class=\"tablepress tablepress-id-19\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Command<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\"><Esc> Key<\/td><td class=\"column-2\">return to command mode<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">i<\/td><td class=\"column-2\">change to insert mode before current cursor position<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">a<\/td><td class=\"column-2\">change to insert mode after current cursor position<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">o<\/td><td class=\"column-2\">change to insert mode but start a new line below current cursor<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-19 from cache -->\n<p>&nbsp;<\/p>\n<h3>Cursor Operations<\/h3>\n\n<table id=\"tablepress-20\" class=\"tablepress tablepress-id-20\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Command<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">[repeat]w<\/td><td class=\"column-2\">move forwards [repeat] words<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">[repeat]b<\/td><td class=\"column-2\">move backwards [repeat] words<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">^<\/td><td class=\"column-2\">move to the beginning of the line<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">0<\/td><td class=\"column-2\">move to the beginning of the line<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">[repeat]f<letter><\/td><td class=\"column-2\">move forwards to the [repeat] instance of <letter><\/td>\n<\/tr>\n<tr class=\"row-7\">\n\t<td class=\"column-1\">[repeat]F<letter><\/td><td class=\"column-2\">move backwards to the [repeat] instance of <letter><\/td>\n<\/tr>\n<tr class=\"row-8\">\n\t<td class=\"column-1\">[number]G<\/td><td class=\"column-2\">move to line [number]<\/td>\n<\/tr>\n<tr class=\"row-9\">\n\t<td class=\"column-1\">H<\/td><td class=\"column-2\">move to the home line (first line on the screen)<\/td>\n<\/tr>\n<tr class=\"row-10\">\n\t<td class=\"column-1\">M<\/td><td class=\"column-2\">move to the middle line (on the screen)<\/td>\n<\/tr>\n<tr class=\"row-11\">\n\t<td class=\"column-1\">L<\/td><td class=\"column-2\">move to the last line (on the screen)<\/td>\n<\/tr>\n<tr class=\"row-12\">\n\t<td class=\"column-1\">(<\/td><td class=\"column-2\">move backwards one sentence<\/td>\n<\/tr>\n<tr class=\"row-13\">\n\t<td class=\"column-1\">)<\/td><td class=\"column-2\">move forwards one sentence<\/td>\n<\/tr>\n<tr class=\"row-14\">\n\t<td class=\"column-1\">{<\/td><td class=\"column-2\">move backwards one paragraph<\/td>\n<\/tr>\n<tr class=\"row-15\">\n\t<td class=\"column-1\">}<\/td><td class=\"column-2\">move forwards one paragraph<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-20 from cache -->\n<p>&nbsp;<\/p>\n<h3>Edit Operations<\/h3>\n\n<table id=\"tablepress-21\" class=\"tablepress tablepress-id-21\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Command<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">u<\/td><td class=\"column-2\">undo<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\"><Ctrl>r<\/td><td class=\"column-2\">redo<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">[repeat]dw<\/td><td class=\"column-2\">delete (cut) [repeat] words<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">[repeat]dd<\/td><td class=\"column-2\">delete (cut) [repeat] lines<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">d$<\/td><td class=\"column-2\">delete (cut) to end of line<\/td>\n<\/tr>\n<tr class=\"row-7\">\n\t<td class=\"column-1\">dG<\/td><td class=\"column-2\">delete (cut) to end of file<\/td>\n<\/tr>\n<tr class=\"row-8\">\n\t<td class=\"column-1\">[repeat]yw<\/td><td class=\"column-2\">yank (copy) [repeat] words<\/td>\n<\/tr>\n<tr class=\"row-9\">\n\t<td class=\"column-1\">[repeat]yy<\/td><td class=\"column-2\">yank (copy) [repeat] lines<\/td>\n<\/tr>\n<tr class=\"row-10\">\n\t<td class=\"column-1\">p<\/td><td class=\"column-2\">put (paste)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-21 from cache -->\n<p>&nbsp;<\/p>\n<h3>Search and Replace<\/h3>\n\n<table id=\"tablepress-22\" class=\"tablepress tablepress-id-22\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Command<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">[repeat]\/<string><\/td><td class=\"column-2\">search forwards to the [repeat] instance of <string><\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">:s\/<old-string>\/<new-string><\/td><td class=\"column-2\">search and replace the first instance of <old-string> with <br \/>\n<new-string> on this line<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">:s\/<old-string>\/<new-string>\/g<\/td><td class=\"column-2\">search and replace all instances of <old-string> with <new-string<br \/>\n> on this line<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">:%s\/<old-string>\/<new-string>\/g<\/td><td class=\"column-2\">search and replace all instances of <old-string> with <new-<br \/>\nstring> in this file<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-22 from cache -->\n<p>&nbsp;<\/p>\n<h3>Getting Help<\/h3>\n<p>:help<\/p>\n<p>&nbsp;<\/p>\n<h3>References<\/h3>\n<div>man vi &#8211; command line documentation<\/div>\n<div><\/div>\n<div>Learning the Vi and Vim Editors, Seventh Edition, <a href=\"http:\/\/openisbn.com\/isbn\/059652983X\">http:\/\/openisbn.com\/isbn\/059652983X<\/a><\/div>\n<div>\n<p>&nbsp;<\/p>\n<h3>Downloading<\/h3>\n<div>You can download a version to run on your local workstation from <a href=\"http:\/\/www.vim.org\/\">http:\/\/www.vim.org\/<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>What is Vi? Vi (pronounced vee-eye) is a text editor available on Super Computing Wales and virtually all Linux and Unix based computers. It was originally developed by Bill Joy in 1976 while he was at the University of California, Berkeley. Vi was designed to run on remote terminals over very slow connections and is [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"class_list":["post-700","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/comments?post=700"}],"version-history":[{"count":13,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/700\/revisions"}],"predecessor-version":[{"id":807,"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/pages\/700\/revisions\/807"}],"wp:attachment":[{"href":"https:\/\/portal.supercomputing.wales\/index.php\/wp-json\/wp\/v2\/media?parent=700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}