Linux Training : b. vi the only editor you need

  • Vim editing of docbook text
  • vi and vim: the text editor of choice

    vi is a text editor. It is not an email client. It is not a web browser. It won't use a synthetic voice to read you your email. It will take a bit of time to learn how to use it effectively but that will pay off greatly. Every *NIX system has vi installed. Most now use the updated version called vim (Vi IMproved). You can find out by looking at the output of which vi and you'll likely see it's an alias to vim.

    vim

    • vim is the improved version of vi that supports syntax highlighting and many new features.

      A few commands to learn quickly

      Esc

      Use the Esc to switch to the command mode. If you are not entering text into a file, you are (or need to be) in command mode. When in doubt, hit Esc so you know what mode you are in. Most vim setups will indicate "-INSERT" at the bottom of the screen when entering text or "- VISUAL --" when in visual mode (used for block text copy/cut/ etc).

      i

      i is for insert mode. Where ever the cursor is when you press "i" is where the text will start being entered and existing text will be shifted to the right.

      :wq

      This how to save the file and exit vi. Esc to command mode. :wq is write then quit

      :q!

      This will exit from vi without saving any changes to the file.

      :r myfile

      This will insert the file myfile at the current cursor position.

      Shift-A

      Go into insert mode at the end of the current line

      x

      Delete the character under the cursor

      dw

      Delete from cursor to end of word (next non alphabet character)

      dd

      Delete the current line

      yy

      Copy the current line into memory

      p

      Paste from memory

      xp

      Swap current letter and next letter with a delete and paste. Very useful to change "teh" to "the".

    Vim editing of docbook text

    Docbook XML is similar to HTML but it uses different tags. The article Vim Macros for Editing DocBook Documents has a set of instructions on how to setup vim shortcuts specifically for editing docbook XML text. The macro files are hard to find so they are available here:
    tagtmps.vim
    mfuncs.vim
    maps.vim
    tfuncs.vim

    Additional links for vi/vim howtos

    vimtutor is the exercise
    • Type "vimtutor" at the command line and work all lessons up through 7.1

    LIN:page top

    Attachments:

    tfuncs.vim (application/octet-stream)
    maps.vim (application/octet-stream)
    mfuncs.vim (application/octet-stream)
    tagtmps.vim (application/octet-stream)