Results 1 to 5 of 5

Thread: vi customization problem

  1. #1
    Join Date
    Aug 2009
    Location
    Mumbai
    Beans
    280
    Distro
    Ubuntu 12.04 Precise Pangolin

    vi customization problem

    I have to work on a really old AIX workstation with vi version 3.10 in it.
    I have done a little work in vim, but that was much more easy to use than the old vi (atleast untill I get used to the old vi).

    Since I have been using the backspace key to erase my previous character for ever since I was born, I would like to have that functionality in vi as well.

    I did search for a solution.

    I found the following:

    1 :set backspace=2 (:set all does not have a backspace option, nor nocompatible)
    2. stty erase ^? (Didn't work)
    3. In .exrc file in my home directory, I can set up a mapping. ie, map <key> <key to be>.
    However, in the edit mode in vi, pressing backspace actually takes my cursor to one position on the left.

    How do I map a supposedly arrow key to make it perform the function of a backspace?
    Last edited by shashanksingh; March 27th, 2013 at 08:18 AM.

  2. #2
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: vi customization problem

    1. Check the output of stty:
      Code:
      $ stty -g|cut -d: -f7
      7f
      or the same in human readable form:
      Code:
      $ stty -a|sed -n 's/.* \(erase [^;]*\).*/\1/p'
      For stty from GNU coreutils this should give
      Code:
      erase = ^?
      For stty on Solaris (and probably on AIX, too):
      Code:
      erase = DEL
    2. Check that the mapping is set up properly:
      Code:
      $ cat ~/.exrc|tr \\b @|sed -n '/:map.* @$/p'|od -cAn
         :   m   a   p   !     177       @  \n
      You should get similar output.
    Last edited by schragge; March 27th, 2013 at 12:07 PM.

  3. #3
    Join Date
    Aug 2009
    Location
    Mumbai
    Beans
    280
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: vi customization problem

    Quote Originally Posted by schragge View Post
    Check the output of stty:
    Code:
    $ stty -g|cut -d: -f7
    -> This gave me 'ff'

    or the same in human readable form:
    Code:
    $ stty -a|sed -n 's/.* \(erase [^;]*\).*/\1/p'
    On AIX -> ' erase = ^? '

    Check that the mapping is set up properly:
    Code:
    $ sed -n '/\ch/p' ~/.exrc|od -aAn
       :   m   a   p   !  sp del  sp  bs  nl
    You should get the same output.
    I haven't really set any mappings in .exrc.
    The problem is when I do 'vi .exrc'
    and type 'map <backspace> ', it moves my cursor one step left to the space. It doesn't put anything after the word map.
    So I was wondering since backspace is acting like an 'h' or 'left arrow', how do I represent it as text?

    In the insert mode: backspace = move cursor one step left
    del = Change case of character
    In the command mode: backspace = function of delete or x
    del = Change case of character

    This is very weird.

  4. #4
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: vi customization problem

    In vi, you enter any control character by quoting it with Ctrl+V (e.g. see this answer). This means: to enter <backspace>, press Ctrl+V Backspace, to enter ^H press Ctrl+V Ctrl+H.

    Another thought. I've compiled and installed the traditional vi. Backspace in it actually deletes characters left of the cursor, although they remain displayed until you exit the insert mode by pressing Esc. This is even documented in the tutorial:
    Notice that when you backspace during an insertion the characters you backspace over are not erased; the cursor moves backwards, and the characters remain on the display. This is often useful if you are planning to type in something similar. In any case the characters disappear when you hit ESC; if you want to get rid of them immediately, hit an ESC and then a again.
    I can also observe the same behaviour in nvi.
    Last edited by schragge; March 27th, 2013 at 05:47 PM.

  5. #5
    Join Date
    Aug 2009
    Location
    Mumbai
    Beans
    280
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: vi customization problem

    Thanks you for the help

    I just realized that my vi has the same behavior (it is version 5 something).

    What I now know is that my delete key puts a ~ in the insert mode, and changes the case in command mode.
    My backspace key in insert mode moves my cursor one left and deletes the character on the cursor (although it will reflect AFTER a mode switch), and in my command mode, it does what Ctrl+x does, i.e., erase character under cursor.

    But when I used vim, backspace and delete worked just as commands in real time at insert mode (a backspace reflected a backspace and del could do what Ctrl+x does).
    Can I possible do that in traditional vi?
    I would also like to map an 'Esc+\' to a 'Tab+Tab', to auto-complete the way it is done in bash.

    Thanks,

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •