You are not logged in.

#1 2015-11-03 19:49:37

azzid
Member
Registered: 2015-08-25
Posts: 10

ex vi vim

I've tried various distributions before now trying arch, and in all other cases there has always been some way to make vim the binary for commands like vi and view. In arch however ex remains the "norm" after installing vim.

$ ls -l /usr/bin/ | grep "\b\(vi\|vim\|ex\)\b"
lrwxrwxrwx 1 root root          2  6 sep 21.34 edit -> ex
-rwxr-xr-t 1 root root     236184  6 sep 21.34 ex
lrwxrwxrwx 1 root root          3 28 sep 17.51 rview -> vim
lrwxrwxrwx 1 root root          3 28 sep 17.51 rvim -> vim
lrwxrwxrwx 1 root root          2  6 sep 21.34 vedit -> ex
lrwxrwxrwx 1 root root          2  6 sep 21.34 vi -> ex
lrwxrwxrwx 1 root root          2  6 sep 21.34 view -> ex
-rwxr-xr-x 1 root root    2372176 28 sep 17.51 vim
lrwxrwxrwx 1 root root          3 28 sep 17.51 vimdiff -> vim

What is the correct way to give ex the foot?

Last edited by azzid (2015-11-03 19:50:16)

Offline

#2 2015-11-03 19:58:27

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,612

Re: ex vi vim

I always just use a shell alias  vi=vim

edit: of course, I usually just type e which is an alias for emacsclient  tongue

Last edited by ewaller (2015-11-03 19:59:36)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#3 2015-11-03 20:52:41

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: ex vi vim

Alternatively to what ewaller suggested you could put some symbolic links into /usr/local/bin, e.g.:

# ln -s /usr/bin/vim /usr/local/bin/vi

It is also possible to replace the symbolic links in /usr/bin, however this requires adding the respective files to the NoExtract variable in /etc/pacman.conf .

Offline

#4 2015-11-03 20:56:20

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: ex vi vim

Ugh. Just set the correct environment variables:

export EDITOR="vim"
export VISUAL="$EDITOR"
export SUDO_EDITOR="$EDITOR"
export FCEDIT="$EDITOR"

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2015-11-03 20:56:39

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,612

Re: ex vi vim

respiranto wrote:

you could put some symbolic links into /usr/local/bin,

.... just ensure that /usr/local/bin is in your PATH before /usr/bin


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#6 2015-11-03 20:59:40

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,612

Re: ex vi vim

jasonwryan wrote:

Ugh. Just set the correct environment variables:

Yeah, but muscle memory from my HP-UX days means I always type "vi ..." not "vim ..."
I do use vim from the command line when I want to edit something quick and simple.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#7 2015-11-03 21:01:05

ayekat
Member
Registered: 2011-01-17
Posts: 1,632

Re: ex vi vim

ewaller wrote:
respiranto wrote:

you could put some symbolic links into /usr/local/bin,

.... just ensure that /usr/local/bin is in your PATH before /usr/bin

... or $HOME/.local/bin smile

Otherwise, what jasonwryan said: well-written Unix applications allow you to configure their behaviour through environment variables.


pkgshackscfgblag

Offline

#8 2015-11-03 21:15:09

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: ex vi vim

jasonwryan wrote:

Ugh. Just set the correct environment variables:

export EDITOR="vim"
export VISUAL="$EDITOR"
export SUDO_EDITOR="$EDITOR"
export FCEDIT="$EDITOR"

That remembers me of an issue I have with /etc/environment where I store such variables.
For some reason it is not sourced when `su' is run.
Is there a way to enable this except for sourcing it from the .bashrc?

Offline

#9 2015-11-03 21:25:25

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: ex vi vim

respiranto wrote:
jasonwryan wrote:

Ugh. Just set the correct environment variables:

export EDITOR="vim"
export VISUAL="$EDITOR"
export SUDO_EDITOR="$EDITOR"
export FCEDIT="$EDITOR"

That remembers me of an issue I have with /etc/environment where I store such variables.
For some reason it is not sourced when `su' is run.
Is there a way to enable this except for sourcing it from the .bashrc?

Thread hijacking, but as it is vaguely related...

See `man su`

For  backward  compatibility,  su  defaults  to not change the current directory and to only set the environment variables HOME and
       SHELL (plus USER and LOGNAME if the target user is not root).

...


-m, -p, --preserve-environment
              Preserve the entire environment, i.e. it does not set HOME, SHELL, USER nor LOGNAME.  This option is ignored if  the  option
              --login is specified.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#10 2015-11-03 21:43:34

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: ex vi vim

jasonwryan wrote:

Thread hijacking, but as it is vaguely related...

Sorry, I didn't found it worth opening a new thread.
If this is seen as further hijacking, any moderator may feel free to remove this post.

jasonwryan wrote:

See `man su`

su(1) wrote:

-m, -p, --preserve-environment
              [...] This option is ignored if  the  option --login is specified.

Which is the option I use in most cases (--login, i.e. `su -'). So I assume, I will do best by actually sourcing /etc/environment from (bash).bashrc .

Offline

#11 2015-11-03 22:31:34

basica
Member
From: Australia
Registered: 2012-10-31
Posts: 217

Re: ex vi vim

yeah, I was surprised when I first used  Arch that vi wasn't symlinked to vim too. In any case, what I do is uninstall vi via pacman -R vi and then symlink:

ln -sv /usr/bin/{vim,vi}

Offline

#12 2015-11-03 22:37:55

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 713

Re: ex vi vim

jasonwryan wrote:

Ugh. Just set the correct environment variables:

export EDITOR="vim"
export VISUAL="$EDITOR"
export SUDO_EDITOR="$EDITOR"
export FCEDIT="$EDITOR"

I think setting the 2nd two is redundant if the first two are set?

Offline

#13 2015-11-03 22:57:26

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: ex vi vim

bulletmark wrote:
jasonwryan wrote:

Ugh. Just set the correct environment variables:

export EDITOR="vim"
export VISUAL="$EDITOR"
export SUDO_EDITOR="$EDITOR"
export FCEDIT="$EDITOR"

I think setting the 2nd two is redundant if the first two are set?

No: there are some use cases, eg.,

man fc wrote:

The value  in  the  FCEDIT
                 variable shall be used as a default when −e is not specified. If FCEDIT is null or unset, ed shall be used as the editor.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#14 2015-11-03 23:00:23

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 713

Re: ex vi vim

@jasonwryan, that is different to what the bash man page says.

Offline

#15 2015-11-03 23:04:43

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: ex vi vim

bulletmark wrote:

@jasonwryan, that is different to what the bash man page says.

Indeed it is. Thanks!


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#16 2015-11-04 19:24:06

azzid
Member
Registered: 2015-08-25
Posts: 10

Re: ex vi vim

jasonwryan wrote:

Ugh. Just set the correct environment variables:

export EDITOR="vim"
export VISUAL="$EDITOR"
export SUDO_EDITOR="$EDITOR"
export FCEDIT="$EDITOR"

Added it to .bashrc:

$ grep export .bashrc 
export EDITOR="vim"
export VISUAL="$EDITOR"
export SUDO_EDITOR="$EDITOR"
export FCEDIT="$EDITOR"

visudo and view (the examples I've tried) still start ex.

Adding links to /usr/local/bin does not work as I expect either:

$ ls -l /usr/local/bin/view
lrwxrwxrwx 1 root root 12  4 nov 20.27 /usr/local/bin/view -> /usr/bin/vim
$ which view
/usr/local/bin/view

Looks ok, but when i run view i still end up in ex, verified by issuing :ve which gave:

Version 4.0 (gritter) 12/25/06

The same command in vim fills the screen with info about the installation.

The vi symlink in /usr/local/bin works however.

Last edited by azzid (2015-11-04 19:41:47)

Offline

#17 2015-11-04 19:44:23

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: ex vi vim

You add it to your .profile or .bash_profile or whatever shell initialisation file you use. This also depends on how you login (which you haven't shared).


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#18 2015-11-04 19:50:42

azzid
Member
Registered: 2015-08-25
Posts: 10

Re: ex vi vim

jasonwryan wrote:

You add it to your .profile or .bash_profile or whatever shell initialisation file you use. This also depends on how you login (which you haven't shared).

All .bash_profile does is source .bashrc:

$ cat .bash_profile 
#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc
$ cat .bashrc 
#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

export EDITOR="vim"
export VISUAL="$EDITOR"
export SUDO_EDITOR="$EDITOR"
export FCEDIT="$EDITOR"

I use GDM which I guess is also what displays the login dialog I use when I login. I enter the shell by starting Terminal from the gnome launcher. Don't think my login process is that special. ;-)


EDIT: moving the exports to .bash_profile and/or (i did both) restarting the terminal i find that view is now launching vim as expected. visudo still refuses.

Last edited by azzid (2015-11-04 19:55:58)

Offline

#19 2015-11-04 20:28:28

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: ex vi vim

azzid wrote:

Adding links to /usr/local/bin does not work as I expect either:

$ ls -l /usr/local/bin/view
lrwxrwxrwx 1 root root 12  4 nov 20.27 /usr/local/bin/view -> /usr/bin/vim
$ which view
/usr/local/bin/view

Looks ok, but when i run view i still end up in ex, verified by issuing :ve which gave:

Version 4.0 (gritter) 12/25/06

The same command in vim fills the screen with info about the installation.

The vi symlink in /usr/local/bin works however.

This is because vim acts differently depending on the name it's called as (argv[0]).
You are still using vim, but it is started in ex read-only (view) mode (equivalent to `vim -e -R').
See also vim(1).
vi however has no such special meaning to vim, so vim works just as usual.

Last edited by respiranto (2015-11-04 20:32:32)

Offline

#20 2015-11-04 23:05:18

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: ex vi vim

azzid wrote:

I use GDM which I guess is also what displays the login dialog I use when I login. I enter the shell by starting Terminal from the gnome launcher. Don't think my login process is that special. ;-)

GDM "helpfully" adopts its own way of setting the environment...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB