Wednesday, December 12, 2012

How to copy the text selected in screen mode into vi editor (hp ux)

Screen Useful links :

http://www.catonmat.net/download/screen.cheat.sheet.pdf

http://neophob.com/2007/04/gnu-screen-cheat-sheet/


Rough draft :
--------------
In putty screen mode, usually we can not scroll back using scroll bars to see the past output logs.
There may be ways to achieve this.  But, I don't know.


For example,  I am having a following screen output, with 2 sessions.



-------------------SCREEN SHOT---------------------------------

bash-2.05b$
Server1 0* ksh   1- ksh  

--------------------------------------------------------------

In Screen 0, let me execute a command which emits lot of output. (For example, 'man ls' command)

I set the editor mode as 'vi'.
If I want to scroll back in this screen, I will go to Screen Escape mode  (Ctrl + a).
[Though I set the Screen Escape mode sequence as (Ctrl + z)]

Then using vi navigation key board commands (like pressing 'k' to move up the cursor, Ctrl + B to move backwards.) go to the desired position to place your cursor.


1.) Press space bar to start your selection.

2.) Navigate through the screen to select the items using 'vi' editor navigation keys.  It is a standard vi command to select from the current cursor position to end of the file.  One best option is, pressing 'G' [shift + g] to go to the bottom of the screen. 

Some times, there may not be enough screen buffer available. Need to find a way how to increase this buffer space.

-------------------------------SCREEN SHOT-------------------------------------------------------
bash-2.05b$ man ls

 ls(1)                                                                 ls(1)

 NAME
      ls, lc, l, ll, lsf, lsr, lsx - list contents of directories

 SYNOPSIS
      ls [-abcdefgilmnopqrstuxACFHLR1] [names]

      lc [-abcdefgilmnopqrstuxACFHLR1] [names]

      l [ls_options] [names]
      ll [ls_options] [names]
      lsf [ls_options] [names]
      lsr [ls_options] [names]
      lsx [ls_options] [names]

 DESCRIPTION
      For each directory argument, the ls command lists the contents of the
      directory.  For each file argument, ls repeats its name and any other
      information requested.  The output is sorted in ascending collation
      order by default (see Environment Variables below).  When no argument
      is given, the current directory is listed.  When several arguments are
      given, the arguments are first sorted appropriately, but file
      arguments appear before directories and their contents.

      If you are a user with appropriate privileges, all files except . and
      .. are listed by default.

      There are three major listing formats.  The format chosen depends on
      whether the output is going to a login device (determined by whether
      output device file is a tty device), and can also be controlled by
      option flags.

      The default format for a login device is to list the contents of
      directories in multicolumn format, with entries sorted vertically by
      column.  (When individual file names (as opposed to directory names)
      appear in the argument list, those file names are always sorted across
      the page rather than down the page in columns because individual file
      names can be arbitrarily long.) If the standard output is not a login
Server1 0* ksh   1- ksh       
----------------------------------------------------------------------

3.) Press space bar again to complete the selection / copy process.

-------------------------------------SCREEN SHOT-------------------------------------------
                specified on the command line, ls evaluates the file
                information and file type to be those of the file referenced
                by the link, and not the link itself. However, ls writes the
                name of the link itself and not the file referenced by the
                link.

           -L   Evaluate the file information and file type for all symbolic
                links (whether named on the command line or encountered in a
                file hierarchy) to be those of the file referenced by the
                link, and not the link itself.  However, ls writes the name
                of the link itself and not the file referenced by the link.
                When -L is used with -l, write the contents of symbolic
                links in the long format.

           -R   Recursively list subdirectories encountered.

           -1   (one) List the file names in single column format regardless
                of the output device.  This forces single column format to
                the user's terminal.

      Specifying more than one of the options in the following mutually
      exclusive pairs is not considered an error: -C and -l (ell), -m and -l
      (ell), -x and -l (ell), -C and -1 (one), -H and -L, and -c and -u.

      ls is known by several shorthand-version names for the various
      formats:

           l    is equivalent to ls -m
           ll   is equivalent to ls -l (ell)
           lsf  is equivalent to ls -F
           lsr  is equivalent to ls -R
           lsx  is equivalent to ls -x
bash-2.05b$
Copied 7568 characters into buffer                                                                                                                     
-----------------------------------------------------------------------------------------------------------

4.) Open your file in vi editor, and get into insert mode by pressing 'i'.

5.) Go to Screen paste mode by pressing, 'Ctrl + a' and ']' keys.

Voila ! All your selected contents are pasted into the file.
Save the file by 'Esc + :wq'.