ult/session4.rst
changeset 61 cfae54ede139
parent 59 8c15077f028d
child 62 780effcd7c5a
equal deleted inserted replaced
60:8a36825e21c5 61:cfae54ede139
   243 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. 
   243 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. 
   244 
   244 
   245 To save the file, use ``:w`` 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. 
   245 To save the file, use ``:w`` 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. 
   246 
   246 
   247 To save a file and continue editing, use ``:w FILENAME``
   247 To save a file and continue editing, use ``:w FILENAME``
   248 The file name is optional. If you donot 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. 
   248 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. 
   249 
   249 
   250 To save file with a new name and continue editing the new file, use ``:saveas FILENAME``
   250 To save file with a new name and continue editing the new file, use ``:saveas FILENAME``
   251 
   251 
   252 To save and quit, use ``:wq``
   252 To save and quit, use ``:wq``
   253 
   253 
   373 +----------------------------------------+---------+
   373 +----------------------------------------+---------+
   374 | Copy/yank an entire line               | ``yy``  |
   374 | Copy/yank an entire line               | ``yy``  |
   375 +----------------------------------------+---------+
   375 +----------------------------------------+---------+
   376 
   376 
   377 Note: You can prefix numbers to any of the commands, to repeat them.
   377 Note: You can prefix numbers to any of the commands, to repeat them.
   378 ppp
   378 
   379 Undo and Redo
   379 Undo and Redo
   380 ~~~~~~~~~~~~~
   380 ~~~~~~~~~~~~~
   381 You can undo almost anything using ``u``. 
   381 You can undo almost anything using ``u``. 
   382 
   382 
   383 To undo the undo command type ``C-r``
   383 To undo the undo command type ``C-r``
   384 
   384 
   385 Searching and Replacing
   385 Searching and Replacing
   386 ~~~~~~~~~~~~~~~~~~~~~~~
   386 ~~~~~~~~~~~~~~~~~~~~~~~
   387 
   387 
   388 +----------------------------------------+---------+
   388 +-----------------------------------------+---------+
   389 | Finding                                          |
   389 | Finding                                           |
   390 +========================================+=========+
   390 +=========================================+=========+
   391 | Next occurence of ``text``, forward    |``\text``|
   391 | Next occurrence of ``text``, forward    |``\text``|
   392 +----------------------------------------+---------+
   392 +-----------------------------------------+---------+
   393 | Next occurence of ``text``, backward   |``?text``|
   393 | Next occurrence of ``text``, backward   |``?text``|
   394 +----------------------------------------+---------+
   394 +-----------------------------------------+---------+
   395 | Search again in the same direction     | ``n``   |
   395 | Search again in the same direction      | ``n``   |
   396 +----------------------------------------+---------+
   396 +-----------------------------------------+---------+
   397 | Search again in the opposite direction | ``N``   |
   397 | Search again in the opposite direction  | ``N``   |
   398 +----------------------------------------+---------+
   398 +-----------------------------------------+---------+
   399 | Next occurence of ``x`` in the line    | ``fx``  |
   399 | Next occurrence of ``x`` in the line    | ``fx``  |
   400 +----------------------------------------+---------+
   400 +-----------------------------------------+---------+
   401 | Previous occurence of ``x`` in the line| ``Fx``  |
   401 | Previous occurrence of ``x`` in the line| ``Fx``  |
   402 +----------------------------------------+---------+
   402 +-----------------------------------------+---------+
   403 
   403 
   404 +---------------------------------------+------------------+
   404 +---------------------------------------+------------------+
   405 | Finding and Replacing                                    |
   405 | Finding and Replacing                                    |
   406 +=======================================+==================+
   406 +=======================================+==================+
   407 | Replace the first instance of ``old`` |``:s/old/new``    |
   407 | Replace the first instance of ``old`` |``:s/old/new``    |
   439 Personalizing your Environment
   439 Personalizing your Environment
   440 ==============================
   440 ==============================
   441 
   441 
   442 .bashrc
   442 .bashrc
   443 -------
   443 -------
   444 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 startup files, when it starts up. 
   444 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. 
   445 
   445 
   446 When bash starts up as an interactive login shell, it reads the files ``/etc/profile``, ``~/.bash_profile``, ``~/.bash_login``, and ``~/.profile`` in that order. 
   446 When bash starts up as an interactive login shell, it reads the files ``/etc/profile``, ``~/.bash_profile``, ``~/.bash_login``, and ``~/.profile`` in that order. 
   447 
   447 
   448 When it is a shell that is not a login shell, ``~/.bashrc`` is read and the commands in it are executed. This can be prevented using the ``--norc`` option. To force bash to use another file, instead of the ``~/.bashrc`` file on startup, the ``--rcfile`` option may be used. 
   448 When it is a shell that is not a login shell, ``~/.bashrc`` is read and the commands in it are executed. This can be prevented using the ``--norc`` option. To force bash to use another file, instead of the ``~/.bashrc`` file on start-up, the ``--rcfile`` option may be used. 
   449 
   449 
   450 Now, you know what you should do, to change the current directory to you Desktop. Just put a ``cd ~/Desktop`` into your ``~/.bashrc`` and you are set!
   450 Now, you know what you should do, to change the current directory to you Desktop. Just put a ``cd ~/Desktop`` into your ``~/.bashrc`` and you are set!
   451 
   451 
   452 This example is quite a simple and lame one. The startup 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 ``.bashrc``. We shall look at them, in the next section where we look at environment variables and ``set`` command.
   452 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 ``.bashrc``. We shall look at them, in the next section where we look at environment variables and ``set`` command.
   453 
   453 
   454 
   454 
   455 .vimrc
   455 .vimrc
   456 ------
   456 ------
   457 ``.vimrc`` is a file similar to ``.bashrc`` for vim. It is a startup 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 ``.vimrc`` file, so that they are automatically set each time vim starts. The recommended place for having your ``.vimrc`` is also your home directory. 
   457 ``.vimrc`` is a file similar to ``.bashrc`` 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 ``.vimrc`` file, so that they are automatically set each time vim starts. The recommended place for having your ``.vimrc`` is also your home directory. 
   458 
   458 
   459 The file ``/etc/vimrc`` is the global config file and shouldn't usually be edited. You can instead edit the ``~/.vimrc`` file that is present in your home folder. 
   459 The file ``/etc/vimrc`` is the global config file and shouldn't usually be edited. You can instead edit the ``~/.vimrc`` file that is present in your home folder. 
   460 
   460 
   461 There are a whole bunch of variables that you could set in the ``.vimrc`` file. You can look at all the options available, using the ``:set all`` command in vim. You could use the ``:help option_name`` 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 ``.vimrc``. You should also look at ``:help vimrc`` for more info on the ``.vimrc`` file. If you already have a ``.vimrc`` file, you can edit it from within vim, using ``:e $MYVIMRC`` command. We shall look at some of the most commonly used options. 
   461 There are a whole bunch of variables that you could set in the ``.vimrc`` file. You can look at all the options available, using the ``:set all`` command in vim. You could use the ``:help option_name`` 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 ``.vimrc``. You should also look at ``:help vimrc`` for more info on the ``.vimrc`` file. If you already have a ``.vimrc`` file, you can edit it from within vim, using ``:e $MYVIMRC`` command. We shall look at some of the most commonly used options. 
   462 
   462