Vi Defaults In 6.x

Home » CentOS » Vi Defaults In 6.x
CentOS 27 Comments

When I use copy/paste text into a window running vi, if there is a single line starting with ‘#’, in the pasted content, it adds a # to all subsequent lines and indents each an additional level. Is there some way to eliminate this bizarre behavior, preferably globally and permanently so I don’t have to repeat some change for every machine/user where I might log in?

27 thoughts on - Vi Defaults In 6.x

  • I discovered exactly the same behaviour in the Sylpheed email editor a few weeks back. Not only with cut-and-paste, but just typing into the editor window. If a line starts with # then every following line after that also gains one as you type.

  • Frank Cox wrote:

    Huh. I just tried it, KDE, rxvt, CentOS 6.3, and don’t see that.
    # ipmitool -o supermicro sel list
    1 | 08/15/2012 | 20:06:32 | Physical Security #0xaa | General Chassis intrusion | Asserted gets just that.

    mark

  • It is probably trying to be smarter than we are and doing something context-sensitive. Try naming the file you are editing something.pl.

  • Les Mikesell wrote:
    Odd. vi trythis.pl, then I highlight from another window
    # semanage fcontext -a -t httpd_sys_content_t ‘/mipav-svn(/.*)?’
    /etc/selinux/targeted/contexts/files/file_contexts.local: line 5 has invalid regex mipav-svn/(*): Invalid preceding regular expression

    , and that’s what I get, with two lines.

    mark

  • +1 for .vimrc config files vi is generally a symlink to vim these days.

    @Les, I’ve seen the auto-comment behavior you speak of. You may want to set formatoptions [0] in your .vimrc

    [0] http://vimdoc.sourceforge.net/htmldoc/change.html#fo-table

    @Joseph:
    You have autoindent specified twice – once in its abbreviated form and then the long version.

    set noai set noautoindent

    —~~.~~—
    Mike
    // SilverTip257 //

  • SilverTip257 wrote:

    Also, unless you want it to act like vi, use `set nocompatible` so that it is then full vim & then your vimrc will have full effect.

    Cheers,

    Phil…

  • From: Les Mikesell

    If you do not want to change the defaults, you could temporarily call vim without the initializations:

  • That’s the effect I want, since I log into a lot of different machines and paste stuff into scripts. But, it doesn’t seem to work. With
    ‘vim -u NONE /tmp/test.pl’ it still does the auto-comment stuff.

  • From: Les Mikesell

    Works for me at least to avoid “crazy” double auto-indent… And it turns off syntax highlighting too. But I have no auto-comment in either modes…

    JD

  • That’s interesting – I don’t think I’ve ever changed any defaults. I’m using the text mode version in a gnome-terminal window in case that makes a difference.

  • Of course, if you don’t care for vim, you can always use the old, simple version by using the command “/bin/vi” instead of “vim” and that should do away with most of the enhancements.

  • * Les Mikesell [08/16/2012 14:23]:

    to avoid this behavior during paste, just do:
    :set paste just before pasting.

    Daniel.

  • Actually, it’s a shell alias. And then, only if “vim” is installed, which it isn’t in some configurations. IIRC, desktop systems have him by default, but server installations do not.

  • The systems where I’d be pasting script contents mostly have the software development package group installed. The aliasing explains why it happens seemingly randomly since I’d sometimes have root’s environment, sometimes not. In any case, the ‘:set paste” mode behavior is what I want. I don’t mind syntax highlighting but it seems extremely bizarre for something pretending to be vi with a default setting to ever, under any conditions, insert something you didn’t type.

  • Gordon Messmer wrote:

    It is neither a symlink nor a shell alias – execpt maybe for platforms that for some reason don’t include vi.

    vi is OSS and the OSS vi is fully POSIX compliant.

    and BTW: vi does not read .vimrc but .exrc

    J

  • Reindl Harald wrote:

    Of course

    You seem to missunderstand that there is a program called “vi” and another program called “vim”.

    J

  • Not on a standard CentOS system.

    [whooper@chef ~]$ /bin/vi –version VIM – Vi IMproved 7.2 (2008 Aug 9, compiled Apr 5 2012 10:17:55)

    On a machine that has the vim-enhanced package installed (care of the files dropped in /etc/profile.d/vim.*:

    $ which vi alias vi=’vim’
    /usr/bin/vim

  • Joerg Schilling wrote:

    This just verifies that you’re playing word games. If you want vi that’s not vim, may I ask which *version* of vi you would consider to be vi – one from, say, Sun OS 3? Or from the Irix that ran on our Indigo in the early/mid-nineties? or one from Tru-64 in the late nineties? or were you insisting on one that ran on a system from the early-to-mid-eighties?

    mark

  • wrote:

    SunOS 3 Vi source not available to the public. Irix Vi source not available to the public. Tru-64 Vi source not available to the public.
    ….

    You currently may have the vi source from aprox. 1979 under a 4 clause BSD license or the current Solaris vi under the CDDL. The latter was POSIX compliant approved.

    J

  • Joerg Schilling wrote:

    And so you assert that if you don’t have a version of vi that is strictly compatible with the 1979 source, and has no improvements or bugfixes, it’s not vi?

    mark

  • My complaint that started this thread turns out to be not so much about vim not being vi compatible when executed with the vi name as that non-root users get a default alias of vi=’vim’, with surprising results. Even though they are both part of the vim package, they act differently.

  • On a CentOS system, “vi” will be a shell alias when the “vim” package is installed. Otherwise it will be a variant of “vim” which is more compatible with the POSIX description of “vi” (though not 100%). As we are discussing CentOS, I believe my statements did not require correction. Thanks.

  • I got curious ;-)

    vim-minimal installs /bin/vi vim-enhanced installs /usr/bin/vim and sets the alias (the “vim” package)

    [falb@xxx ~]$ which vi alias vi=’vim’
    /usr/bin/vim
    [falb@xxx ~]$ which vim
    /usr/bin/vim
    [falb@xxx ~]$ whereis vi vi: /bin/vi /usr/share/man/man1/vi.1.gz /usr/share/man/man1p/vi.1p.gz

    But the alias is not set for root!

    [root@xxx ~]# which vi
    /bin/vi
    [root@xxx ~]# which vim
    /usr/bin/vim

  • > /usr/bin/vim

    FWIW, If you comment out the line “[ -n “$ID” -a “$ID” -le 200 ] && return” in
    /etc/profile.d/vim.sh then the alias will be set at login.

    Regards,

LEAVE A COMMENT