web/html/ch03-session4.html~
changeset 0 8083d21c0020
equal deleted inserted replaced
-1:000000000000 0:8083d21c0020
       
     1 <html>
       
     2 <head>
       
     3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
       
     4 <title>Chapter 1. </title>
       
     5 <link rel="stylesheet" href="/review/support/styles.css" type="text/css">
       
     6 <meta name="generator" content="DocBook XSL Stylesheets V1.74.3">
       
     7 <link rel="shortcut icon" type="image/png" href="/review/support/figs/favicon.png">
       
     8 <script type="text/javascript" src="/review/support/jquery-min.js"></script>
       
     9 <script type="text/javascript" src="/review/support/form.js"></script>
       
    10 <script type="text/javascript" src="/review/support/hsbook.js"></script>
       
    11 </head>
       
    12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
       
    13 <div class="chapter" id="ch03-session4">
       
    14 <div class="titlepage"></div>
       
    15 <div class="toc">
       
    16 <p><b>Table of Contents</b></p>
       
    17 <dl>
       
    18 <dt><span class="article"><a href="#id2404065">More text processing</a></span></dt>
       
    19 <dd><dl>
       
    20 <dt><span class="section"><a href="#uniq">1. 
       
    21       <code class="literal">uniq</code>
       
    22     </a></span></dt>
       
    23 <dt><span class="section"><a href="#join">2.       <code class="literal">join</code>
       
    24     </a></span></dt>
       
    25 <dt><span class="section"><a href="#generating-a-word-frequency-list">3. Generating a word frequency list</a></span></dt>
       
    26 <dt><span class="section"><a href="#basic-editing-and-editors">4. Basic editing and editors</a></span></dt>
       
    27 <dd><dl>
       
    28 <dt><span class="section"><a href="#vim">4.1. vim</a></span></dt>
       
    29 <dt><span class="section"><a href="#scite">4.2. SciTE</a></span></dt>
       
    30 </dl></dd>
       
    31 <dt><span class="section"><a href="#personalizing-your-environment">5. Personalizing your Environment</a></span></dt>
       
    32 <dd><dl>
       
    33 <dt><span class="section"><a href="#bashrc">5.1. .bashrc</a></span></dt>
       
    34 <dt><span class="section"><a href="#vimrc">5.2. .vimrc</a></span></dt>
       
    35 </dl></dd>
       
    36 <dt><span class="section"><a href="#subshells-and-source">6. Subshells and 
       
    37       <code class="literal">source</code>
       
    38     </a></span></dt>
       
    39 </dl></dd>
       
    40 </dl>
       
    41 </div>
       
    42 <div class="article" title="More text processing">
       
    43 <div class="titlepage">
       
    44 <div><div><h2 class="title">
       
    45 <a name="id2404065"></a>More text processing</h2></div></div>
       
    46 <hr>
       
    47 </div>
       
    48 <div class="toc">
       
    49 <p><b>Table of Contents</b></p>
       
    50 <dl>
       
    51 <dt><span class="section"><a href="#uniq">1. 
       
    52       <code class="literal">uniq</code>
       
    53     </a></span></dt>
       
    54 <dt><span class="section"><a href="#join">2.       <code class="literal">join</code>
       
    55     </a></span></dt>
       
    56 <dt><span class="section"><a href="#generating-a-word-frequency-list">3. Generating a word frequency list</a></span></dt>
       
    57 <dt><span class="section"><a href="#basic-editing-and-editors">4. Basic editing and editors</a></span></dt>
       
    58 <dd><dl>
       
    59 <dt><span class="section"><a href="#vim">4.1. vim</a></span></dt>
       
    60 <dt><span class="section"><a href="#scite">4.2. SciTE</a></span></dt>
       
    61 </dl></dd>
       
    62 <dt><span class="section"><a href="#personalizing-your-environment">5. Personalizing your Environment</a></span></dt>
       
    63 <dd><dl>
       
    64 <dt><span class="section"><a href="#bashrc">5.1. .bashrc</a></span></dt>
       
    65 <dt><span class="section"><a href="#vimrc">5.2. .vimrc</a></span></dt>
       
    66 </dl></dd>
       
    67 <dt><span class="section"><a href="#subshells-and-source">6. Subshells and 
       
    68       <code class="literal">source</code>
       
    69     </a></span></dt>
       
    70 </dl>
       
    71 </div>
       
    72 <code class="literal">sort</code><p id="x_e"></a>Let's say we have a file which lists a few of the stalwarts of the open source community and a few details about them, like their "other" name, their homepage address, and what they are well known for or their claim to fame.</p>
       
    73 <pre class="programlisting">Richard Stallman%rms%GNU Project
       
    74 Eric Raymond%ESR%Jargon File
       
    75 Ian Murdock% %Debian
       
    76 Lawrence Lessig% %Creative Commons
       
    77 Linus Torvalds% %Linux Kernel
       
    78 Guido van Rossum%BDFL%Python
       
    79 Larry Wall% %Perl
       
    80 
       
    81 
       
    82 </pre>
       
    83 <p id="x_f"></a>The sort command enables us to do this in a flash! Just running the sort command with the file name as a parameter sorts the lines of the file alphabetically and prints the output on the terminal. :</p>
       
    84 <pre class="programlisting">$ sort stalwarts.txt 
       
    85 Eric Raymond%ESR%Jargon File
       
    86 Guido van Rossum%BDFL%Python
       
    87 Ian Murdock% %Debian
       
    88 Larry Wall% %Perl
       
    89 Lawrence Lessig% %Creative Commons
       
    90 Linus Torvalds% %Linux Kernel
       
    91 Richard Stallman%rms%GNU Project
       
    92 
       
    93 </pre>
       
    94 <p id="x_10"></a>If you wish to sort them reverse alphabetically, you just need to pass the 
       
    95     <code class="literal">-r</code> option. Now, you might want to sort the lines, based on each person's claim to fame or their "other" name. What do we do in that case?
       
    96   </p>
       
    97 <p id="x_11"></a>Below is an example that sorts the file based on "other" names. :</p>
       
    98 <pre class="programlisting">$ sort -t % -k 2,2  stalwarts.txt
       
    99 
       
   100 Ian Murdock% %Debian
       
   101 Larry Wall% %Perl
       
   102 Lawrence Lessig% %Creative Commons
       
   103 Linus Torvalds% %Linux Kernel
       
   104 Guido van Rossum%BDFL%Python
       
   105 Eric Raymond%ESR%Jargon File
       
   106 Richard Stallman%rms%GNU Project
       
   107 
       
   108 </pre>
       
   109 <p id="x_12"></a>Sort command assumes white space to be the default delimiter for columns in each line. The 
       
   110     <code class="literal">-t</code> option specifies the delimiting character, which is 
       
   111     <code class="literal">%</code> in this case.
       
   112   </p>
       
   113 <p id="x_13"></a>The 
       
   114     <code class="literal">-k</code> option starts a key at position 2 and ends it at 2, essentially telling the sort command that it should sort based on the 2nd column, which is the other name. 
       
   115     <code class="literal">sort</code> also supports conflict resolution using multiple columns for sorting. You can see that the first three lines have nothing in the "other" names column. We could resolve the conflict by sorting based on the project names (the 3rd column).
       
   116   </p>
       
   117 <pre class="programlisting">$ sort -t % -k 2,2 -k 3,3  stalwarts.txt
       
   118 
       
   119 Lawrence Lessig% %Creative Commons
       
   120 Ian Murdock% %Debian
       
   121 Linus Torvalds% %Linux Kernel
       
   122 Larry Wall% %Perl
       
   123 Guido van Rossum%BDFL%Python
       
   124 Eric Raymond%ESR%Jargon File
       
   125 Richard Stallman%rms%GNU Project
       
   126 
       
   127 </pre>
       
   128 <p id="x_14"></a>    <code class="literal">sort</code> also has a lot of other options like ignoring case differences, month sort(JAN&lt;FEB&lt;...), merging already sorted files. 
       
   129     <code class="literal">man sort</code> would give you a lot of information.
       
   130   </p>
       
   131 <div class="section" title="1.  uniq">
       
   132 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
       
   133 <a name="uniq"></a>1. 
       
   134       <code class="literal">uniq</code>
       
   135     </h2></div></div></div>
       
   136 <p id="x_15"></a>Suppose we have a list of items, say books, and we wish to obtain a list which names of all the books only once, without any duplicates. We use the 
       
   137       <code class="literal">uniq</code> command to achieve this.
       
   138     </p>
       
   139 <pre class="programlisting">Programming Pearls
       
   140 The C Programming Language
       
   141 The Mythical Man Month: Essays on Software Engineering 
       
   142 Programming Pearls
       
   143 The C Programming Language
       
   144 Structure and Interpretation of Computer Programs
       
   145 Programming Pearls
       
   146 Compilers: Principles, Techniques, and Tools
       
   147 The C Programming Language
       
   148 The Art of UNIX Programming
       
   149 Programming Pearls
       
   150 The Art of Computer Programming
       
   151 Introduction to Algorithms
       
   152 The Art of UNIX Programming
       
   153 The Pragmatic Programmer: From Journeyman to Master
       
   154 Programming Pearls
       
   155 Unix Power Tools
       
   156 The Art of UNIX Programming
       
   157 
       
   158 </pre>
       
   159 <p id="x_16"></a>Let us try and get rid of the duplicate lines from this file using the 
       
   160       <code class="literal">uniq</code> command.
       
   161     </p>
       
   162 <pre class="programlisting">$ uniq items.txt 
       
   163 Programming Pearls
       
   164 The C Programming Language
       
   165 The Mythical Man Month: Essays on Software Engineering 
       
   166 Programming Pearls
       
   167 The C Programming Language
       
   168 Structure and Interpretation of Computer Programs
       
   169 Programming Pearls
       
   170 Compilers: Principles, Techniques, and Tools
       
   171 The C Programming Language
       
   172 The Art of UNIX Programming
       
   173 Programming Pearls
       
   174 The Art of Computer Programming
       
   175 Introduction to Algorithms
       
   176 The Art of UNIX Programming
       
   177 The Pragmatic Programmer: From Journeyman to Master
       
   178 Programming Pearls
       
   179 Unix Power Tools
       
   180 The Art of UNIX Programming
       
   181 
       
   182 </pre>
       
   183 <p id="x_17"></a>Nothing happens! Why? The 
       
   184       <code class="literal">uniq</code> command removes duplicate lines only when they are next to each other. So, we get a sorted file from the original file and work with that file, henceforth.
       
   185     </p>
       
   186 <pre class="programlisting">$ sort items.txt &gt; items-sorted.txt
       
   187 $ uniq items-sorted.txt
       
   188 Compilers: Principles, Techniques, and Tools
       
   189 Introduction to Algorithms
       
   190 Programming Pearls
       
   191 Structure and Interpretation of Computer Programs
       
   192 The Art of Computer Programming
       
   193 The Art of UNIX Programming
       
   194 The C Programming Language
       
   195 The Mythical Man Month: Essays on Software Engineering 
       
   196 The Pragmatic Programmer: From Journeyman to Master
       
   197 Unix Power Tools
       
   198 
       
   199 </pre>
       
   200 <p id="x_18"></a>      <code class="literal">uniq -u</code> command gives the lines which are unique and do not have any duplicates in the file. 
       
   201       <code class="literal">uniq -d</code> outputs only those lines which have duplicates. The 
       
   202       <code class="literal">-c</code> option displays the number of times each line occurs in the file. :
       
   203     </p>
       
   204 <pre class="programlisting">$ uniq -u items-sorted.txt 
       
   205 Compilers: Principles, Techniques, and Tools
       
   206 Introduction to Algorithms
       
   207 Structure and Interpretation of Computer Programs
       
   208 The Art of Computer Programming
       
   209 The Mythical Man Month: Essays on Software Engineering 
       
   210 The Pragmatic Programmer: From Journeyman to Master
       
   211 Unix Power Tools
       
   212 
       
   213 $ uniq -dc items-sorted.txt      
       
   214 5 Programming Pearls
       
   215 3 The Art of UNIX Programming
       
   216 3 The C Programming Language
       
   217 
       
   218 
       
   219 </pre>
       
   220 </div>
       
   221 <div class="section" title="2.  join">
       
   222 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
       
   223 <a name="join"></a>2.       <code class="literal">join</code>
       
   224     </h2></div></div></div>
       
   225 <p id="x_19"></a>Now suppose we had the file 
       
   226       <code class="literal">stalwarts1.txt</code>, which lists the home pages of all the people listed in 
       
   227       <code class="literal">stalwarts.txt</code>. :
       
   228     </p>
       
   229 <pre class="programlisting">Richard Stallman%http://www.stallman.org
       
   230 Eric Raymond%http://www.catb.org/~esr/
       
   231 Ian Murdock%http://ianmurdock.com/
       
   232 Lawrence Lessig%http://lessig.org
       
   233 Linus Torvalds%http://torvalds-family.blogspot.com/
       
   234 Guido van Rossum%http://www.python.org/~guido/
       
   235 Larry Wall%http://www.wall.org/~larry/
       
   236 
       
   237 </pre>
       
   238 <p id="x_1a"></a>It would be nice to have a single file with the information in both the files. To achieve this we use the 
       
   239       <code class="literal">join</code> command. :
       
   240     </p>
       
   241 <pre class="programlisting">$ join stalwarts.txt stalwarts1.txt -t %
       
   242 Richard Stallman%rms%GNU Project%http://www.stallman.org
       
   243 Eric Raymond%ESR%Jargon File%http://www.catb.org/~esr/
       
   244 Ian Murdock% %Debian%http://ianmurdock.com/
       
   245 Lawrence Lessig% %Creative Commons%http://lessig.org
       
   246 Linus Torvalds% %Linux Kernel%http://torvalds-family.blogspot.com/
       
   247 Guido van Rossum%BDFL%Python%http://www.python.org/~guido/
       
   248 Larry Wall% %Perl%http://www.wall.org/~larry/
       
   249 
       
   250 </pre>
       
   251 <p id="x_1b"></a>The 
       
   252       <code class="literal">join</code> command joins the two files, based on the common field present in both the files, which is the name, in this case.
       
   253     </p>
       
   254 <p id="x_1c"></a>The 
       
   255       <code class="literal">-t</code> option again specifies the delimiting character. Unless that is specified, join assumes that the fields are separated by spaces.
       
   256     </p>
       
   257 <p id="x_1d"></a>Note that, for 
       
   258       <code class="literal">join</code> to work, the common field should be in the same order in both the files. If this is not so, you could use 
       
   259       <code class="literal">sort</code>, to sort the files on the common field and then join the files. In the above example, we have the common field to be the first column in both the files. If this is not the case we could use the 
       
   260       <code class="literal">-1</code> and 
       
   261       <code class="literal">-2</code> options to specify the field to be used for joining the files. :
       
   262     </p>
       
   263 <pre class="programlisting">$ join -2 2 stalwarts.txt stalwarts2.txt -t %
       
   264 Richard Stallman%rms%GNU Project%http://www.stallman.org
       
   265 Eric Raymond%ESR%Jargon File%http://www.catb.org/~esr/
       
   266 Ian Murdock% %Debian%http://ianmurdock.com/
       
   267 Lawrence Lessig% %Creative Commons%http://lessig.org
       
   268 Linus Torvalds% %Linux Kernel%http://torvalds-family.blogspot.com/
       
   269 Guido van Rossum%BDFL%Python%http://www.python.org/~guido/
       
   270 Larry Wall% %Perl%http://www.wall.org/~larry/
       
   271 
       
   272 
       
   273 </pre>
       
   274 </div>
       
   275 <div class="section" title="3. Generating a word frequency list">
       
   276 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
       
   277 <a name="generating-a-word-frequency-list"></a>3. Generating a word frequency list</h2></div></div></div>
       
   278 <p id="x_1e"></a>Now, let us use the tools we have learnt to use, to generate a word frequency list of a text file. We shall use the free text of Alice in Wonderland.</p>
       
   279 <p id="x_1f"></a>The basic steps to achieve this task would be -</p>
       
   280 <div class="orderedlist"><ol class="orderedlist" type="1">
       
   281 <li class="listitem"><p id="x_20"></a>Eliminate the punctuation and spaces from the document.</p></li>
       
   282 <li class="listitem"><p id="x_21"></a>Generate a list of words.</p></li>
       
   283 <li class="listitem"><p id="x_22"></a>Count the words.</p></li>
       
   284 </ol></div>
       
   285 <p id="x_23"></a>We first use 
       
   286       <code class="literal">grep</code> and some elementary 
       
   287       <code class="literal">regex</code> to eliminate the non-alpha-characters. :
       
   288     </p>
       
   289 <pre class="programlisting">$ grep "[A-Za-z]*" alice-in-wonderland.txt
       
   290 
       
   291 </pre>
       
   292 <p id="x_24"></a>This outputs all the lines which has any alphabetic characters on it. This isn't of much use, since we haven't done anything with the code. We only require the alphabetic characters, without any of the other junk. 
       
   293       <code class="literal">man grep</code> shows us the 
       
   294       <code class="literal">-o</code> option for outputting only the text which matches the regular expression. :
       
   295     </p>
       
   296 <pre class="programlisting">$ grep "[A-Za-z]*" -o alice-in-wonderland.txt
       
   297 
       
   298 </pre>
       
   299 <p id="x_25"></a>Not very surprisingly, we have all the words, spit out in the form of a list! Now that we have a list of words, it is quite simple to count the occurrences of the words. You would've realized that we can make use of 
       
   300       <code class="literal">sort</code> and 
       
   301       <code class="literal">uniq</code> commands. We pipe the output from the 
       
   302       <code class="literal">grep</code> to the 
       
   303       <code class="literal">sort</code> and then pipe it's output to 
       
   304       <code class="literal">uniq</code>. :
       
   305     </p>
       
   306 <pre class="programlisting">$ grep "[A-Za-z]*" -o alice-in-wonderland.txt | sort | uniq -c 
       
   307 
       
   308 </pre>
       
   309 <p id="x_26"></a>Notice that you get the list of all words in the document in the alphabetical order, with it's frequency written next to it. But, you might have observed that Capitalized words and lower case words are being counted as different words. We therefore, replace all the Upper case characters with lower case ones, using the 
       
   310       <code class="literal">tr</code> command. :
       
   311     </p>
       
   312 <pre class="programlisting">$ grep  "[A-Za-z]*" -o alice-in-wonderland.txt | tr 'A-Z' 'a-z' | sort | uniq -c 
       
   313 
       
   314 </pre>
       
   315 <p id="x_27"></a>Now, it would also be nice to have the list ordered in the decreasing order of the frequency of the appearance of the words. We sort the output of the 
       
   316       <code class="literal">uniq</code> command with 
       
   317       <code class="literal">-n</code> and 
       
   318       <code class="literal">-r</code> options, to get the desired output. :
       
   319     </p>
       
   320 <pre class="programlisting">$ grep  "[A-Za-z]*" -o alice-in-wonderland.txt | tr 'A-Z' 'a-z' | sort | uniq -c | sort -nr
       
   321 
       
   322 </pre>
       
   323 </div>
       
   324 <div class="section" title="4. Basic editing and editors">
       
   325 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
       
   326 <a name="basic-editing-and-editors"></a>4. Basic editing and editors</h2></div></div></div>
       
   327 <div class="section" title="4.1. vim">
       
   328 <div class="titlepage"><div><div><h3 class="title">
       
   329 <a name="vim"></a>4.1. vim</h3></div></div></div>
       
   330 <p id="x_28"></a>Vim is a very powerful editor. It has a lot of commands, and all of them cannot be explained here. We shall try and look at a few, so that you can find your way around in vim.</p>
       
   331 <p id="x_29"></a>To open a file in vim, we pass the filename as a parameter to the 
       
   332         <code class="literal">vim</code> command. If a file with that filename does not exist, a new file is created. :
       
   333       </p>
       
   334 <pre class="programlisting">$ vim first.txt
       
   335 
       
   336 </pre>
       
   337 <p id="x_2a"></a>To start inserting text into the new file that we have opened, we need to press the 
       
   338         <code class="literal">i</code> key. This will take us into the 
       
   339         <span class="emphasis"><em>insert</em></span> mode from the 
       
   340         <span class="emphasis"><em>command</em></span> mode. Hitting the 
       
   341         <code class="literal">esc</code> key, will bring us back to the 
       
   342         <span class="emphasis"><em>command</em></span> mode. There is also another mode of vim, called the 
       
   343         <span class="emphasis"><em>visual</em></span> mode which will be discussed later in the course.
       
   344       </p>
       
   345 <p id="x_2b"></a>In general, it is good to spend as little time as possible in the insert mode and extensively use the command mode to achieve various tasks.</p>
       
   346 <p id="x_2c"></a>To save the file, use 
       
   347         <code class="literal">:w</code> in the command mode. From here on, it is understood that we are in the command mode, whenever we are issuing any command to vim.
       
   348       </p>
       
   349 <p id="x_2d"></a>To save a file and continue editing, use 
       
   350         <code class="literal">:w FILENAME</code> The file name is optional. If you do not specify a filename, it is saved in the same file that you opened. If a file name different from the one you opened is specified, the text is saved with the new name, but you continue editing the file that you opened. The next time you save it without specifying a name, it gets saved with the name of the file that you initially opened.
       
   351       </p>
       
   352 <p id="x_2e"></a>To save file with a new name and continue editing the new file, use 
       
   353         <code class="literal">:saveas FILENAME</code>
       
   354       </p>
       
   355 <p id="x_2f"></a>To save and quit, use 
       
   356         <code class="literal">:wq</code>
       
   357       </p>
       
   358 <p id="x_30"></a>To quit, use 
       
   359         <code class="literal">:q</code>
       
   360       </p>
       
   361 <p id="x_31"></a>To quit without saving, use 
       
   362         <code class="literal">:q!</code>
       
   363       </p>
       
   364 <div class="section" title="4.1.1. Moving around">
       
   365 <div class="titlepage"><div><div><h4 class="title">
       
   366 <a name="moving-around"></a>4.1.1. Moving around</h4></div></div></div>
       
   367 <p id="x_32"></a>While you are typing in a file, it is in-convenient to keep moving your fingers from the standard position for typing to the arrow keys. Vim, therefore, provides alternate keys for moving in the document. Note again that, you should be in the command mode, when issuing any commands to vim.</p>
       
   368 <p id="x_33"></a>The basic cursor movement can be achieved using the keys, 
       
   369           <code class="literal">h</code> (left), 
       
   370           <code class="literal">l</code> (right), 
       
   371           <code class="literal">k</code> (up) and 
       
   372           <code class="literal">j</code> (down). :
       
   373         </p>
       
   374 <pre class="programlisting">^
       
   375 k              
       
   376 </pre>
       
   377 <div class="variablelist"><dl>
       
   378 <dt><span class="term">&lt; h       l &gt;</span></dt>
       
   379 <dd>
       
   380 <p></p>
       
   381 <p id="x_34"></a>j v</p>
       
   382 </dd>
       
   383 </dl></div>
       
   384 <p id="x_35"></a>Note: Most commands can be prefixed with a number, to repeat the command. For instance, 
       
   385           <code class="literal">10j</code> will move the cursor down 10 lines.
       
   386         </p>
       
   387 <div class="section" title="4.1.1.1. Moving within a line">
       
   388 <div class="titlepage"><div><div><h5 class="title">
       
   389 <a name="moving-within-a-line"></a>4.1.1.1. Moving within a line</h5></div></div></div>
       
   390 <div class="informaltable"><table border="1">
       
   391 <colgroup>
       
   392 <col width="41">
       
   393 <col width="10">
       
   394 </colgroup>
       
   395 <thead><tr>
       
   396 <th>
       
   397                     <p id="x_36"></a>Cursor Movement</p>
       
   398                   </th>
       
   399 <th>
       
   400                     <p id="x_37"></a>Command</p>
       
   401                   </th>
       
   402 </tr></thead>
       
   403 <tbody>
       
   404 <tr>
       
   405 <td>
       
   406                     <p id="x_38"></a>Beginning of line</p>
       
   407                   </td>
       
   408 <td>
       
   409                     <p id="x_39"></a>
       
   410                       <code class="literal">0</code>
       
   411                     </p>
       
   412                   </td>
       
   413 </tr>
       
   414 <tr>
       
   415 <td>
       
   416                     <p id="x_3a"></a>First non-space character of line</p>
       
   417                   </td>
       
   418 <td>
       
   419                     <p id="x_3b"></a>
       
   420                       <code class="literal">^</code>
       
   421                     </p>
       
   422                   </td>
       
   423 </tr>
       
   424 <tr>
       
   425 <td>
       
   426                     <p id="x_3c"></a>End of line</p>
       
   427                   </td>
       
   428 <td>
       
   429                     <p id="x_3d"></a>
       
   430                       <code class="literal">$</code>
       
   431                     </p>
       
   432                   </td>
       
   433 </tr>
       
   434 <tr>
       
   435 <td>
       
   436                     <p id="x_3e"></a>Last non-space character of line</p>
       
   437                   </td>
       
   438 <td>
       
   439                     <p id="x_3f"></a>
       
   440                       <code class="literal">g_</code>
       
   441                     </p>
       
   442                   </td>
       
   443 </tr>
       
   444 </tbody>
       
   445 </table></div>
       
   446 </div>
       
   447 <div class="section" title="4.1.1.2. Moving by words and sentences">
       
   448 <div class="titlepage"><div><div><h5 class="title">
       
   449 <a name="moving-by-words-and-sentences"></a>4.1.1.2. Moving by words and sentences</h5></div></div></div>
       
   450 <div class="informaltable"><table border="1">
       
   451 <colgroup>
       
   452 <col width="31">
       
   453 <col width="10">
       
   454 </colgroup>
       
   455 <thead><tr>
       
   456 <th>
       
   457                     <p id="x_40"></a>Cursor Movement</p>
       
   458                   </th>
       
   459 <th>
       
   460                     <p id="x_41"></a>Command</p>
       
   461                   </th>
       
   462 </tr></thead>
       
   463 <tbody>
       
   464 <tr>
       
   465 <td>
       
   466                     <p id="x_42"></a>Forward, word beginning</p>
       
   467                   </td>
       
   468 <td>
       
   469                     <p id="x_43"></a>
       
   470                       <code class="literal">w</code>
       
   471                     </p>
       
   472                   </td>
       
   473 </tr>
       
   474 <tr>
       
   475 <td>
       
   476                     <p id="x_44"></a>Backward, word beginning</p>
       
   477                   </td>
       
   478 <td>
       
   479                     <p id="x_45"></a>
       
   480                       <code class="literal">b</code>
       
   481                     </p>
       
   482                   </td>
       
   483 </tr>
       
   484 <tr>
       
   485 <td>
       
   486                     <p id="x_46"></a>Forward, word end</p>
       
   487                   </td>
       
   488 <td>
       
   489                     <p id="x_47"></a>
       
   490                       <code class="literal">e</code>
       
   491                     </p>
       
   492                   </td>
       
   493 </tr>
       
   494 <tr>
       
   495 <td>
       
   496                     <p id="x_48"></a>Backward, word end</p>
       
   497                   </td>
       
   498 <td>
       
   499                     <p id="x_49"></a>
       
   500                       <code class="literal">ge</code>
       
   501                     </p>
       
   502                   </td>
       
   503 </tr>
       
   504 <tr>
       
   505 <td>
       
   506                     <p id="x_4a"></a>Forward, sentence beginning</p>
       
   507                   </td>
       
   508 <td>
       
   509                     <p id="x_4b"></a>
       
   510                       <code class="literal">)</code>
       
   511                     </p>
       
   512                   </td>
       
   513 </tr>
       
   514 <tr>
       
   515 <td>
       
   516                     <p id="x_4c"></a>Backward, sentence beginning</p>
       
   517                   </td>
       
   518 <td>
       
   519                     <p id="x_4d"></a>
       
   520                       <code class="literal">(</code>
       
   521                     </p>
       
   522                   </td>
       
   523 </tr>
       
   524 <tr>
       
   525 <td>
       
   526                     <p id="x_4e"></a>Forward, paragraph beginning</p>
       
   527                   </td>
       
   528 <td>
       
   529                     <p id="x_4f"></a>
       
   530                       <code class="literal">}</code>
       
   531                     </p>
       
   532                   </td>
       
   533 </tr>
       
   534 <tr>
       
   535 <td>
       
   536                     <p id="x_50"></a>Backward, paragraph beginning</p>
       
   537                   </td>
       
   538 <td>
       
   539                     <p id="x_51"></a>
       
   540                       <code class="literal">{</code>
       
   541                     </p>
       
   542                   </td>
       
   543 </tr>
       
   544 </tbody>
       
   545 </table></div>
       
   546 </div>
       
   547 <div class="section" title="4.1.1.3. More movement commands">
       
   548 <div class="titlepage"><div><div><h5 class="title">
       
   549 <a name="more-movement-commands"></a>4.1.1.3. More movement commands</h5></div></div></div>
       
   550 <div class="informaltable"><table border="1">
       
   551 <colgroup>
       
   552 <col width="34">
       
   553 <col width="13">
       
   554 </colgroup>
       
   555 <thead><tr>
       
   556 <th>
       
   557                     <p id="x_52"></a>Cursor Movement</p>
       
   558                   </th>
       
   559 <th>
       
   560                     <p id="x_53"></a>Command</p>
       
   561                   </th>
       
   562 </tr></thead>
       
   563 <tbody>
       
   564 <tr>
       
   565 <td>
       
   566                     <p id="x_54"></a>Forward by a screenful of text</p>
       
   567                   </td>
       
   568 <td>
       
   569                     <p id="x_55"></a>
       
   570                       <code class="literal">C-f</code>
       
   571                     </p>
       
   572                   </td>
       
   573 </tr>
       
   574 <tr>
       
   575 <td>
       
   576                     <p id="x_56"></a>Backward by a screenful of text</p>
       
   577                   </td>
       
   578 <td>
       
   579                     <p id="x_57"></a>
       
   580                       <code class="literal">C-b</code>
       
   581                     </p>
       
   582                   </td>
       
   583 </tr>
       
   584 <tr>
       
   585 <td>
       
   586                     <p id="x_58"></a>Beginning of the screen</p>
       
   587                   </td>
       
   588 <td>
       
   589                     <p id="x_59"></a>
       
   590                       <code class="literal">H</code>
       
   591                     </p>
       
   592                   </td>
       
   593 </tr>
       
   594 <tr>
       
   595 <td>
       
   596                     <p id="x_5a"></a>Middle of the screen</p>
       
   597                   </td>
       
   598 <td>
       
   599                     <p id="x_5b"></a>
       
   600                       <code class="literal">M</code>
       
   601                     </p>
       
   602                   </td>
       
   603 </tr>
       
   604 <tr>
       
   605 <td>
       
   606                     <p id="x_5c"></a>End of the screen</p>
       
   607                   </td>
       
   608 <td>
       
   609                     <p id="x_5d"></a>
       
   610                       <code class="literal">L</code>
       
   611                     </p>
       
   612                   </td>
       
   613 </tr>
       
   614 <tr>
       
   615 <td>
       
   616                     <p id="x_5e"></a>End of file</p>
       
   617                   </td>
       
   618 <td>
       
   619                     <p id="x_5f"></a>
       
   620                       <code class="literal">G</code>
       
   621                     </p>
       
   622                   </td>
       
   623 </tr>
       
   624 <tr>
       
   625 <td>
       
   626                     <p id="x_60"></a>Line number 
       
   627                       <code class="literal">num</code>
       
   628                     </p>
       
   629                   </td>
       
   630 <td>
       
   631                     <p id="x_61"></a>
       
   632                       <code class="literal">[num]G</code>
       
   633                     </p>
       
   634                   </td>
       
   635 </tr>
       
   636 <tr>
       
   637 <td>
       
   638                     <p id="x_62"></a>Beginning of file</p>
       
   639                   </td>
       
   640 <td>
       
   641                     <p id="x_63"></a>
       
   642                       <code class="literal">gg</code>
       
   643                     </p>
       
   644                   </td>
       
   645 </tr>
       
   646 <tr>
       
   647 <td>
       
   648                     <p id="x_64"></a>Next occurrence of the text under the cursor</p>
       
   649                   </td>
       
   650 <td>
       
   651                     <div class="variablelist"><dl>
       
   652 <dt><span class="term">
       
   653                           <code class="literal">*</code>
       
   654                         </span></dt>
       
   655 <dd><p></p></dd>
       
   656 </dl></div>
       
   657                   </td>
       
   658 </tr>
       
   659 <tr>
       
   660 <td>
       
   661                     <p id="x_65"></a>Previous occurrence of the text under the cursor</p>
       
   662                   </td>
       
   663 <td>
       
   664                     <div class="variablelist"><dl>
       
   665 <dt><span class="term">
       
   666                           <code class="literal">#</code>
       
   667                         </span></dt>
       
   668 <dd><p></p></dd>
       
   669 </dl></div>
       
   670                   </td>
       
   671 </tr>
       
   672 </tbody>
       
   673 </table></div>
       
   674 <p id="x_66"></a>Note: 
       
   675             <code class="literal">C-x</code> is 
       
   676             <code class="literal">Ctrl</code> + 
       
   677             <code class="literal">x</code>
       
   678           </p>
       
   679 </div>
       
   680 </div>
       
   681 <div class="section" title="4.1.2. The visual mode">
       
   682 <div class="titlepage"><div><div><h4 class="title">
       
   683 <a name="the-visual-mode"></a>4.1.2. The visual mode</h4></div></div></div>
       
   684 <p id="x_67"></a>The visual mode is a special mode that is not present in the original vi editor. It allows us to highlight text and perform actions on it. All the movement commands that have been discussed till now work in the visual mode also. The editing commands that will be discussed in the future work on the visual blocks selected, too.</p>
       
   685 </div>
       
   686 <div class="section" title="4.1.3. Editing commands">
       
   687 <div class="titlepage"><div><div><h4 class="title">
       
   688 <a name="editing-commands"></a>4.1.3. Editing commands</h4></div></div></div>
       
   689 <p id="x_68"></a>The editing commands usually take the movements as arguments. A movement is equivalent to a selection in the visual mode. The cursor is assumed to have moved over the text in between the initial and the final points of the movement. The motion or the visual block that's been highlighted can be passed as arguments to the editing commands.</p>
       
   690 <div class="informaltable"><table border="1">
       
   691 <colgroup>
       
   692 <col width="26">
       
   693 <col width="10">
       
   694 </colgroup>
       
   695 <thead><tr>
       
   696 <th>
       
   697                   <p id="x_69"></a>Editing effect</p>
       
   698                 </th>
       
   699 <th>
       
   700                   <p id="x_6a"></a>Command</p>
       
   701                 </th>
       
   702 </tr></thead>
       
   703 <tbody>
       
   704 <tr>
       
   705 <td>
       
   706                   <p id="x_6b"></a>Cutting text</p>
       
   707                 </td>
       
   708 <td>
       
   709                   <p id="x_6c"></a>
       
   710                     <code class="literal">d</code>
       
   711                   </p>
       
   712                 </td>
       
   713 </tr>
       
   714 <tr>
       
   715 <td>
       
   716                   <p id="x_6d"></a>Copying/Yanking text</p>
       
   717                 </td>
       
   718 <td>
       
   719                   <p id="x_6e"></a>
       
   720                     <code class="literal">y</code>
       
   721                   </p>
       
   722                 </td>
       
   723 </tr>
       
   724 <tr>
       
   725 <td>
       
   726                   <p id="x_6f"></a>Pasting copied/cut text</p>
       
   727                 </td>
       
   728 <td>
       
   729                   <p id="x_70"></a>
       
   730                     <code class="literal">p</code>
       
   731                   </p>
       
   732                 </td>
       
   733 </tr>
       
   734 </tbody>
       
   735 </table></div>
       
   736 <p id="x_71"></a>The cut and copy commands take the motions or visual blocks as arguments and act on them. For instance, if you wish to delete the text from the current text position to the beginning of the next word, type 
       
   737           <code class="literal">dw</code>. If you wish to copy the text from the current position to the end of this sentence, type 
       
   738           <code class="literal">y)</code>.
       
   739         </p>
       
   740 <p id="x_72"></a>Apart from the above commands, that take any motion or visual block as an argument, there are additional special commands.</p>
       
   741 <div class="informaltable"><table border="1">
       
   742 <colgroup>
       
   743 <col width="41">
       
   744 <col width="10">
       
   745 </colgroup>
       
   746 <thead><tr>
       
   747 <th>
       
   748                   <p id="x_73"></a>Editing effect</p>
       
   749                 </th>
       
   750 <th>
       
   751                   <p id="x_74"></a>Command</p>
       
   752                 </th>
       
   753 </tr></thead>
       
   754 <tbody>
       
   755 <tr>
       
   756 <td>
       
   757                   <p id="x_75"></a>Cut the character under the cursor</p>
       
   758                 </td>
       
   759 <td>
       
   760                   <p id="x_76"></a>
       
   761                     <code class="literal">x</code>
       
   762                   </p>
       
   763                 </td>
       
   764 </tr>
       
   765 <tr>
       
   766 <td>
       
   767                   <p id="x_77"></a>Replace the character under the cursor with 
       
   768                     <code class="literal">a</code>
       
   769                   </p>
       
   770                 </td>
       
   771 <td>
       
   772                   <div class="variablelist"><dl>
       
   773 <dt><span class="term">
       
   774                         <code class="literal">ra</code>
       
   775                       </span></dt>
       
   776 <dd><p></p></dd>
       
   777 </dl></div>
       
   778                 </td>
       
   779 </tr>
       
   780 <tr>
       
   781 <td>
       
   782                   <p id="x_78"></a>Cut an entire line</p>
       
   783                 </td>
       
   784 <td>
       
   785                   <p id="x_79"></a>
       
   786                     <code class="literal">dd</code>
       
   787                   </p>
       
   788                 </td>
       
   789 </tr>
       
   790 <tr>
       
   791 <td>
       
   792                   <p id="x_7a"></a>Copy/yank an entire line</p>
       
   793                 </td>
       
   794 <td>
       
   795                   <p id="x_7b"></a>
       
   796                     <code class="literal">yy</code>
       
   797                   </p>
       
   798                 </td>
       
   799 </tr>
       
   800 </tbody>
       
   801 </table></div>
       
   802 <p id="x_7c"></a>Note: You can prefix numbers to any of the commands, to repeat them.</p>
       
   803 </div>
       
   804 <div class="section" title="4.1.4. Undo and Redo">
       
   805 <div class="titlepage"><div><div><h4 class="title">
       
   806 <a name="undo-and-redo"></a>4.1.4. Undo and Redo</h4></div></div></div>
       
   807 <p id="x_7d"></a>You can undo almost anything using 
       
   808           <code class="literal">u</code>.
       
   809         </p>
       
   810 <p id="x_7e"></a>To undo the undo command type 
       
   811           <code class="literal">C-r</code>
       
   812         </p>
       
   813 </div>
       
   814 <div class="section" title="4.1.5. Searching and Replacing">
       
   815 <div class="titlepage"><div><div><h4 class="title">
       
   816 <a name="searching-and-replacing"></a>4.1.5. Searching and Replacing</h4></div></div></div>
       
   817 <div class="informaltable"><table border="1">
       
   818 <colgroup>
       
   819 <col width="42">
       
   820 <col width="10">
       
   821 </colgroup>
       
   822 <thead><tr>
       
   823 <th>
       
   824                   <p id="x_7f"></a>Finding</p>
       
   825                 </th>
       
   826 <th>
       
   827                   <p id="x_80"></a>Command</p>
       
   828                 </th>
       
   829 </tr></thead>
       
   830 <tbody>
       
   831 <tr>
       
   832 <td>
       
   833                   <p id="x_81"></a>Next occurrence of 
       
   834                     <code class="literal">text</code>, forward
       
   835                   </p>
       
   836                 </td>
       
   837 <td>
       
   838                   <p id="x_82"></a>
       
   839                     <code class="literal">\text</code>
       
   840                   </p>
       
   841                 </td>
       
   842 </tr>
       
   843 <tr>
       
   844 <td>
       
   845                   <p id="x_83"></a>Next occurrence of 
       
   846                     <code class="literal">text</code>, backward
       
   847                   </p>
       
   848                 </td>
       
   849 <td>
       
   850                   <p id="x_84"></a>
       
   851                     <code class="literal">?text</code>
       
   852                   </p>
       
   853                 </td>
       
   854 </tr>
       
   855 <tr>
       
   856 <td>
       
   857                   <p id="x_85"></a>Search again in the same direction</p>
       
   858                 </td>
       
   859 <td>
       
   860                   <p id="x_86"></a>
       
   861                     <code class="literal">n</code>
       
   862                   </p>
       
   863                 </td>
       
   864 </tr>
       
   865 <tr>
       
   866 <td>
       
   867                   <p id="x_87"></a>Search again in the opposite direction</p>
       
   868                 </td>
       
   869 <td>
       
   870                   <p id="x_88"></a>
       
   871                     <code class="literal">N</code>
       
   872                   </p>
       
   873                 </td>
       
   874 </tr>
       
   875 <tr>
       
   876 <td>
       
   877                   <p id="x_89"></a>Next occurrence of 
       
   878                     <code class="literal">x</code> in the line
       
   879                   </p>
       
   880                 </td>
       
   881 <td>
       
   882                   <p id="x_8a"></a>
       
   883                     <code class="literal">fx</code>
       
   884                   </p>
       
   885                 </td>
       
   886 </tr>
       
   887 <tr>
       
   888 <td>
       
   889                   <p id="x_8b"></a>Previous occurrence of 
       
   890                     <code class="literal">x</code> in the line
       
   891                   </p>
       
   892                 </td>
       
   893 <td>
       
   894                   <p id="x_8c"></a>
       
   895                     <code class="literal">Fx</code>
       
   896                   </p>
       
   897                 </td>
       
   898 </tr>
       
   899 </tbody>
       
   900 </table></div>
       
   901 <div class="informaltable"><table border="1">
       
   902 <colgroup>
       
   903 <col width="40">
       
   904 <col width="19">
       
   905 </colgroup>
       
   906 <thead><tr>
       
   907 <th>
       
   908                   <p id="x_8d"></a>Finding and Replacing</p>
       
   909                 </th>
       
   910 <th>
       
   911                   <p id="x_8e"></a>Command</p>
       
   912                 </th>
       
   913 </tr></thead>
       
   914 <tbody>
       
   915 <tr>
       
   916 <td>
       
   917                   <p id="x_8f"></a>Replace the first instance of 
       
   918                     <code class="literal">old</code> with 
       
   919                     <code class="literal">new</code> in the current line.
       
   920                   </p>
       
   921                 </td>
       
   922 <td>
       
   923                   <p id="x_90"></a>
       
   924                     <code class="literal">:s/old/new</code>
       
   925                   </p>
       
   926                 </td>
       
   927 </tr>
       
   928 <tr>
       
   929 <td>
       
   930                   <p id="x_91"></a>Replace all instances of 
       
   931                     <code class="literal">old</code> with 
       
   932                     <code class="literal">new</code> in the current line.
       
   933                   </p>
       
   934                 </td>
       
   935 <td>
       
   936                   <p id="x_92"></a>
       
   937                     <code class="literal">:s/old/new/g</code>
       
   938                   </p>
       
   939                 </td>
       
   940 </tr>
       
   941 <tr>
       
   942 <td>
       
   943                   <p id="x_93"></a>Replace all instances of 
       
   944                     <code class="literal">old</code> with 
       
   945                     <code class="literal">new</code> in the current line, but ask for confirmation each time.
       
   946                   </p>
       
   947                 </td>
       
   948 <td>
       
   949                   <p id="x_94"></a>
       
   950                     <code class="literal">:s/old/new/gc</code>
       
   951                   </p>
       
   952                 </td>
       
   953 </tr>
       
   954 <tr>
       
   955 <td>
       
   956                   <p id="x_95"></a>Replace the first instance of 
       
   957                     <code class="literal">old</code> with 
       
   958                     <code class="literal">new</code> in the entire file.
       
   959                   </p>
       
   960                 </td>
       
   961 <td>
       
   962                   <p id="x_96"></a>
       
   963                     <code class="literal">:%s/old/new</code>
       
   964                   </p>
       
   965                 </td>
       
   966 </tr>
       
   967 <tr>
       
   968 <td>
       
   969                   <p id="x_97"></a>Replace all instances of 
       
   970                     <code class="literal">old</code> with 
       
   971                     <code class="literal">new</code> in the entire file.
       
   972                   </p>
       
   973                 </td>
       
   974 <td>
       
   975                   <p id="x_98"></a>
       
   976                     <code class="literal">:%s/old/new/g</code>
       
   977                   </p>
       
   978                 </td>
       
   979 </tr>
       
   980 <tr>
       
   981 <td>
       
   982                   <p id="x_99"></a>Replace all instances of 
       
   983                     <code class="literal">old</code> with 
       
   984                     <code class="literal">new</code> in the entire file but ask for confirmation each time.
       
   985                   </p>
       
   986                 </td>
       
   987 <td>
       
   988                   <p id="x_9a"></a>
       
   989                     <code class="literal">:%s/old/new/gc</code>
       
   990                   </p>
       
   991                 </td>
       
   992 </tr>
       
   993 </tbody>
       
   994 </table></div>
       
   995 </div>
       
   996 </div>
       
   997 <div class="section" title="4.2. SciTE">
       
   998 <div class="titlepage"><div><div><h3 class="title">
       
   999 <a name="scite"></a>4.2. SciTE</h3></div></div></div>
       
  1000 <p id="x_9b"></a>SciTE is a 
       
  1001         <span class="emphasis"><em>source code</em></span> editor, that has a feel similar to the commonly used GUI text editors. It has a wide range of features that are extremely useful for a programmer, editing code. Also it aims to keep configuration simple, and the user needs to edit a text file to configure SciTE to his/her liking.
       
  1002       </p>
       
  1003 <p id="x_9c"></a>Opening, Saving, Editing files with SciTE is extremely simple and trivial. Knowledge of using a text editor will suffice.</p>
       
  1004 <p id="x_9d"></a>SciTE can syntax highlight code in various languages. It also has auto-indentation, code-folding and other such features which are useful when editing code.</p>
       
  1005 <p id="x_9e"></a>SciTE also gives you the option to (compile and) run your code, from within the editor.</p>
       
  1006 </div>
       
  1007 </div>
       
  1008 <div class="section" title="5. Personalizing your Environment">
       
  1009 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
       
  1010 <a name="personalizing-your-environment"></a>5. Personalizing your Environment</h2></div></div></div>
       
  1011 <div class="section" title="5.1. .bashrc">
       
  1012 <div class="titlepage"><div><div><h3 class="title">
       
  1013 <a name="bashrc"></a>5.1. .bashrc</h3></div></div></div>
       
  1014 <p id="x_9f"></a>What would you do, if you want bash to execute a particular command each time you start it up? For instance, say you want the current directory to be your Desktop instead of your home folder, each time bash starts up. How would you achieve this? Bash reads and executes commands in a whole bunch of files called start-up files, when it starts up.</p>
       
  1015 <p id="x_a0"></a>When bash starts up as an interactive login shell, it reads the files 
       
  1016         <code class="literal">/etc/profile</code>, 
       
  1017         <code class="literal">~/.bash_profile</code>, 
       
  1018         <code class="literal">~/.bash_login</code>, and 
       
  1019         <code class="literal">~/.profile</code> in that order.
       
  1020       </p>
       
  1021 <p id="x_a1"></a>When it is a shell that is not a login shell, 
       
  1022         <code class="literal">~/.bashrc</code> is read and the commands in it are executed. This can be prevented using the 
       
  1023         <code class="literal">--norc</code> option. To force bash to use another file, instead of the 
       
  1024         <code class="literal">~/.bashrc</code> file on start-up, the 
       
  1025         <code class="literal">--rcfile</code> option may be used.
       
  1026       </p>
       
  1027 <p id="x_a2"></a>Now, you know what you should do, to change the current directory to you Desktop. Just put a 
       
  1028         <code class="literal">cd ~/Desktop</code> into your 
       
  1029         <code class="literal">~/.bashrc</code> and you are set!
       
  1030       </p>
       
  1031 <p id="x_a3"></a>This example is quite a simple and lame one. The start-up files are used for a lot more complex things than this. You could set (or unset) aliases and a whole bunch of environment variables in the 
       
  1032         <code class="literal">.bashrc</code>. We shall look at them, in the next section where we look at environment variables and 
       
  1033         <code class="literal">set</code> command.
       
  1034       </p>
       
  1035 </div>
       
  1036 <div class="section" title="5.2. .vimrc">
       
  1037 <div class="titlepage"><div><div><h3 class="title">
       
  1038 <a name="vimrc"></a>5.2. .vimrc</h3></div></div></div>
       
  1039 <p id="x_a4"></a>
       
  1040         <code class="literal">.vimrc</code> is a file similar to 
       
  1041         <code class="literal">.bashrc</code> for vim. It is a start-up file that vim reads and executes, each time it starts up. The options that you would like to be set every time you use vim, are placed in the 
       
  1042         <code class="literal">.vimrc</code> file, so that they are automatically set each time vim starts. The recommended place for having your 
       
  1043         <code class="literal">.vimrc</code> is also your home directory.
       
  1044       </p>
       
  1045 <p id="x_a5"></a>The file 
       
  1046         <code class="literal">/etc/vimrc</code> is the global config file and shouldn't usually be edited. You can instead edit the 
       
  1047         <code class="literal">~/.vimrc</code> file that is present in your home folder.
       
  1048       </p>
       
  1049 <p id="x_a6"></a>There are a whole bunch of variables that you could set in the 
       
  1050         <code class="literal">.vimrc</code> file. You can look at all the options available, using the 
       
  1051         <code class="literal">:set all</code> command in vim. You could use the 
       
  1052         <code class="literal">:help option_name</code> to get more information about the option that you want to set. Once you are comfortable with what you want to set a particular variable to, you could add it to 
       
  1053         <code class="literal">.vimrc</code>. You should also look at 
       
  1054         <code class="literal">:help vimrc</code> for more info on the 
       
  1055         <code class="literal">.vimrc</code> file. If you already have a 
       
  1056         <code class="literal">.vimrc</code> file, you can edit it from within vim, using 
       
  1057         <code class="literal">:e $MYVIMRC</code> command. We shall look at some of the most commonly used options.
       
  1058       </p>
       
  1059 <div class="informaltable"><table border="1">
       
  1060 <colgroup>
       
  1061 <col width="35">
       
  1062 <col width="84">
       
  1063 </colgroup>
       
  1064 <thead><tr>
       
  1065 <th>
       
  1066                 <p id="x_a7"></a>Command</p>
       
  1067               </th>
       
  1068 <th>
       
  1069                 <p id="x_a8"></a>Vim action</p>
       
  1070               </th>
       
  1071 </tr></thead>
       
  1072 <tbody>
       
  1073 <tr>
       
  1074 <td>
       
  1075                 <p id="x_a9"></a>
       
  1076                   <code class="literal">set nocompatible</code>
       
  1077                 </p>
       
  1078               </td>
       
  1079 <td>
       
  1080                 <p id="x_aa"></a>Explicitly disable compatibility with vi</p>
       
  1081               </td>
       
  1082 </tr>
       
  1083 <tr>
       
  1084 <td>
       
  1085                 <div class="variablelist"><dl>
       
  1086 <dt><span class="term">
       
  1087                       <code class="literal">set backspace=indent,eol,start</code>
       
  1088                     </span></dt>
       
  1089 <dd><p></p></dd>
       
  1090 </dl></div>
       
  1091               </td>
       
  1092 <td>
       
  1093                 <p id="x_ab"></a>In the insert mode, vim allows the backspace key to delete white spaces at the start of line, line breaks and the character before which insert mode started.</p>
       
  1094               </td>
       
  1095 </tr>
       
  1096 <tr>
       
  1097 <td>
       
  1098                 <p id="x_ac"></a>set autoindent</p>
       
  1099               </td>
       
  1100 <td>
       
  1101                 <p id="x_ad"></a>Vim indents a new line with the same indentation of the previous line.</p>
       
  1102               </td>
       
  1103 </tr>
       
  1104 <tr>
       
  1105 <td>
       
  1106                 <p id="x_ae"></a>set backup</p>
       
  1107               </td>
       
  1108 <td>
       
  1109                 <p id="x_af"></a>Vim keeps a backup copy of a file when overwriting it.</p>
       
  1110               </td>
       
  1111 </tr>
       
  1112 <tr>
       
  1113 <td>
       
  1114                 <p id="x_b0"></a>set history=50</p>
       
  1115               </td>
       
  1116 <td>
       
  1117                 <p id="x_b1"></a>Vim keeps 50 commands and 50 search patterns in the history.</p>
       
  1118               </td>
       
  1119 </tr>
       
  1120 <tr>
       
  1121 <td>
       
  1122                 <p id="x_b2"></a>set ruler</p>
       
  1123               </td>
       
  1124 <td>
       
  1125                 <p id="x_b3"></a>Displays the current cursor position in the lower right corner of the vim window.</p>
       
  1126               </td>
       
  1127 </tr>
       
  1128 <tr>
       
  1129 <td>
       
  1130                 <p id="x_b4"></a>set showcmd</p>
       
  1131               </td>
       
  1132 <td>
       
  1133                 <p id="x_b5"></a>Displays the incomplete command in the lower right corner.</p>
       
  1134               </td>
       
  1135 </tr>
       
  1136 <tr>
       
  1137 <td>
       
  1138                 <p id="x_b6"></a>set incsearch</p>
       
  1139               </td>
       
  1140 <td>
       
  1141                 <p id="x_b7"></a>Turns on incremental searching. Displays search results while you type.</p>
       
  1142               </td>
       
  1143 </tr>
       
  1144 </tbody>
       
  1145 </table></div>
       
  1146 <p id="x_b8"></a>You can see the effect of the changes made to your 
       
  1147         <code class="literal">.vimrc</code> file by restarting vim. If you want to see the changes that you made to your 
       
  1148         <code class="literal">.vimrc</code> file immediately, you could source the file from within vim.
       
  1149       </p>
       
  1150 <p id="x_b9"></a>If the 
       
  1151         <code class="literal">.vimrc</code> file has been sourced when this instance of vim was started, you could just resource the file again:
       
  1152       </p>
       
  1153 <p id="x_ba"></a>:so $MYVIMRC</p>
       
  1154 <p id="x_bb"></a>If you just created the 
       
  1155         <code class="literal">.vimrc</code> file or it was not sourced when you stared this instance of vim, just replace the 
       
  1156         <code class="literal">$MYVIMRC</code> variable above, with the location of the 
       
  1157         <code class="literal">.vimrc</code> file that you created/edited.
       
  1158       </p>
       
  1159 </div>
       
  1160 </div>
       
  1161 <div class="section" title="6. Subshells and source">
       
  1162 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
       
  1163 <a name="subshells-and-source"></a>6. Subshells and 
       
  1164       <code class="literal">source</code>
       
  1165     </h2></div></div></div>
       
  1166 <p id="x_bc"></a>A subshell is just a separate instance of the shell which is a child process of the shell that launches it. Bash creates a subshell in various circumstances. Creation of subshells allows the execution of various processes simultaneously.</p>
       
  1167 <div class="blockquote"><blockquote class="blockquote"><div class="itemizedlist"><ul class="itemizedlist" type="*">
       
  1168 <li class="listitem" style="list-style-type: *"><p id="x_bd"></a>When an external command is executed, a new subshell is created. Any built-in commands of bash are executed with int the same shell, and no new subshell is started. When an external command is run, the bash shell copies itself (along with it's environment) creating a subshell and the process is changed to the external command executed. The subshell is a child process of this shell.</p></li>
       
  1169 <li class="listitem" style="list-style-type: *"><p id="x_be"></a>Any pipes being used, create a subshell. The commands on the input and output ends of the pipe are run in different subshells.</p></li>
       
  1170 <li class="listitem" style="list-style-type: *"><p id="x_bf"></a>You could also, explicitly tell bash to start a subshell by enclosing a list of commands between parentheses. Each of the commands in the list is executed within a single new subshell.</p></li>
       
  1171 </ul></div></blockquote></div>
       
  1172 <p id="x_c0"></a>To avoid creating a subshell, when running a shell script, you could use the 
       
  1173       <code class="literal">source</code> command. :
       
  1174     </p>
       
  1175 <pre class="programlisting">$ source script.sh
       
  1176 
       
  1177 </pre>
       
  1178 <p id="x_c1"></a>This will run the 
       
  1179       <code class="literal">script.sh</code> within the present shell without creating a subshell. The 
       
  1180       <code class="literal">.</code> command is an alias for the source command. 
       
  1181       <code class="literal">. script.sh</code> is therefore equivalent to 
       
  1182       <code class="literal">source script.sh</code>.
       
  1183     </p>
       
  1184 </div>
       
  1185 </div>
       
  1186 </div></body>
       
  1187 </html>