1. Editors

    The Modeling Center workstations offer several ASCII text editors for working with input and data files: kedit, gedit, vi and vim.

    1. kedit and gedit are menu-based text editors; kedit is available on all machines, and gedit on the older ones. Type "kedit" or "gedit" in a shell window to start them. Since neither will list the "dot files" on its File Open menu, to edit those you must type, for example, "kedit .bashrc"

      1. Their simple functions are accessed from the Menu bar across the top of the kedit or gedit window. They provide means for opening, saving, and closing files, selecting text, and cutting and pasting. They are very similar to Notepad under Windoze.

      2. Since kedit and gedit are ASCII editors, no formatting is possible other than word wrap; since data files often do not conform to standard 78 column letter format, leaving word wrap turned off usually is a good idea.

      3. Although these editors are easy to use, they have two major disadvantages: they are much less powerful than vi, the UNIX editor (below); and as GL programs, they cannot be used over a remote (telnet) connection. Hence learning at least the rudiments of vi is an excellent idea.

    2. vi and vim - The UNIX text editor

      vi is a line editor, meaning that its functions normally are executed line by line or word by word. Vim is a somewhat improved version of vi. Both operate in two modes: command and edit. Some edit functions can be carried out within command mode. All of the commands below work in both editors.

      1. To start vi type vi 'fname'; if 'fname' does not exist it will be created; several files may be loaded at once by concatenating filenames; to move to next one, type 'n'; start vim similarly.

      2. To enter Command Mode type : [colon]

        The following commands can be issued in command mode; type the colon to enter command mode, type the command, and press enter.

        Command Action Comments
        :q Leave vi :q! Insist on leaving
        :w 'fname' writes the current file to disk as 'fname' if a file of that name already exists, it will be overwritten
        :lnumber1, lnumber2 w 'fname' writes the portion of the current file from linenumber1 to linenumber2 to 'fname' :set nu to see line numbers
        :x save and quit :wq does the same thing

    3. Movement in file

      These commands are not prefaced with a colon. They allow movement of the cursor within a file for viewing or to reach the point where editing is to begin.

      Command Action
      - (dash) or <up arrow> up a line
      <> or <down arrow> down a line
      <backspace>
      or <left arrow>
      left a character
      <spacebar>
      or <right arrow>
      right a character
      $ to end of line
      ^ to beginning of line
      H to top of screen
      L to bottom of screen
      M to middle of screen
      <Ctrl>D down a half page
      <Ctrl> U up a half page
      <Ctrl> F down a whole page
      <Ctrl> B up a whole page
      'lnumber' G to a specific line ('lnumber' is a numeral)
      :set nu display the line numbers
      G go to the end of the file
      /'text' search for 'text', forward in file
      ?'text' search for 'text', backward in file
      n search for next instance of text found
      N go back to previous instance of text found

    4. Editing in Command Mode

      A few editing commands can be used without entering insert mode:

      Command Action Comments
      x delete character under cursor  
      nx deletes n characters n is a numeral
      dd delete current line  
      ndd deletes n lines n is a numeral
      p enters most recently dd'd text following cursor = paste after cursor
      P pastes in front of cursor  
      yy yank; copies line to paste buffer paste with p or P
      O <Esc> insert blank line above cursor  
      o <Esc> insert blank line below cursor  
      r 'newchar' replace character at cursor with 'newchar' i.e., overtype one character
      R 'newchars' replace several characters i.e., overtype multiple characters
      :r 'fname' inserts file 'fname' in current file at the cursor 'fname' must be a text file
      All replace commands put vi in insert mode; type <esc> to return to command mode.
      u undo most recent change  
      . (period) repeat last command  

    5. Insert Mode Editing

      Putting vi into insert mode causes it to behave more or less like a standard ASCII text editor. Once insert mode is entered, vi remains in insert mode until <esc> is pressed; commands from command mode are not executed, but rather entered as text, so be watchful.

      Command Action Comments
      i enter insert mode text fills left of cursor
      a enter insert mode text fills right of cursor
      I insert text at beginning of line  
      A insert text at end of line  
      <Esc> exit insert mode  


      This page last modified 1:17 PM on Tuesday August 24th, 2010.
      Webmaster, Department of Chemistry, University of Maine, Orono, ME 04469