LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   less and vi (for Slack users). (https://www.linuxquestions.org/questions/slackware-14/less-and-vi-for-slack-users-4175464312/)

stf92 06-01-2013 12:00 AM

less and vi (for Slack users).
 
Hi: To change from an O.S to a new version of it can be upsetting. Example: When in slackware 12.0, when seeing text files with less, I sometimes made a little correction. I pressed 'v' and in this way entered vi. The tiny correction done, I returned to less. Now I have 14.0. If I press the 'v' key, again vi is invoked. But now vi comes with different default settings and, as a result, it's impossible for me to make the most elementary change to the edited file. I have two options: either make vi behave as before, by changieng its settings or make vim, whose default settings have not been changed, the less editor. Unfortunately it's not an easy thing to do either of these. I thought instructing less to use vim instead of vi would be an easy thing. After studying its man page for some hours, I had to give up. This of course is not slackware but plain linux. If you do not know how to do it, do not blame but your own ignorance, I mean.

Diantre 06-01-2013 12:09 AM

Set $VISUAL or $EDITOR in your environment to whatever editor you prefer, less will use $VISUAL first, if not set, it uses $EDITOR. It's actually very simple... :)

From the less manpage:
Code:

      v      Invokes an editor to edit the current file  being  viewed.  The  editor  is
              taken  from  the environment variable VISUAL if defined, or EDITOR if VISUAL
              is not defined, or defaults to "vi" if neither VISUAL nor EDITOR is defined.
              See also the discussion of LESSEDIT under the section on PROMPTS below.


stf92 06-01-2013 12:18 AM

Quote:

Originally Posted by Diantre (Post 4963222)
Set $VISUAL or $EDITOR in your environment to whatever editor you prefer, less will use $VISUAL first, if not set, it uses $EDITOR. It's actually very simple... :)

I did it:
Code:

semoi@server:~$ v /usr/bin/vim 
-rwxr-xr-x 1 root root 2097864 2012-08-29 13:33 /usr/bin/vim*
semoi@server:~$ VISUAL=/usr/bin/vim
semoi@server:~$ echo $VISUAL
/usr/bin/vim
semoi@server:~$

But less still invokes vi!

astrogeek 06-01-2013 12:24 AM

On a default Slackware vi is actually a symlink to elvis.

To make vi use vim for all uses, probably what you want, do this as root:

Code:

cd /usr/bin
rm vi
ln -s vim vi

then vi will invoke vim for all purposes.

Diantre 06-01-2013 12:34 AM

Quote:

Originally Posted by stf92 (Post 4963226)
But less still invokes vi!

Well, I don't know then. In my system that only happens if VISUAL or EDITOR aren't defined. Maybe you could try exporting the variables or changing the vi symlink as astrogeek suggests.

stf92 06-01-2013 12:39 AM

OK. But I am studying vi/elvis looking forward to use it as an editor. I would rather prefer operating at the less level. I wrote the assignment

VISUAL="/usr/bin/vim"

in /etc/profile. And I booted the machine. But still less invokes vi and not vim. There must be something odd in the settings of my O.S. (slackware 14.0). Maybe I'd rather post a thread in the linuxquestions>slackware forum.

stf92 06-01-2013 12:47 AM

In /etc/profile, I added 'export' before the assigment. Now it is

export VISUAL=/usr/bin/vim

And now I get vim, in less. The 'export' token made all the difference!

Diantre 06-01-2013 12:53 AM

Quote:

Originally Posted by stf92 (Post 4963232)
I wrote the assignment

VISUAL="/usr/bin/vim"

in /etc/profile.

I use ~/.bashrc for that:

Code:

export VISUAL=vim
export EDITOR=vim

Quote:

Originally Posted by stf92 (Post 4963232)
Maybe I'd rather post a thread in the linuxquestions>slackware forum.

You just did. ;)

stf92 06-01-2013 12:58 AM

If I put it in /home/my_directory/.bashrc then I will have to put in /root/.bashrc too and in my girl friend's directory as well. Using /etc/profile, I'm making the setting system wide.

But why is it necessary to export the variable. If I don't export it, after boot I can see it anyway (echo $VISUAL), THOUGH it's obvious that less does not.

Diantre 06-01-2013 02:59 AM

Quote:

Originally Posted by stf92 (Post 4963238)
But why is it necessary to export the variable. If I don't export it, after boot I can see it anyway (echo $VISUAL), THOUGH it's obvious that less does not.

It's necessary to export the variables so subprocesses can use them. When you declare a variable as VAR=value, that's a shell variable. When the export keyword is used, the variable becomes an environment variable, and is available to subprocesses, 'less' in this case. More info here.

stf92 06-01-2013 03:16 AM

Are not the variables output by the set command without arguments all of them environment variables? You mean that if, in /etc/profile, I don't prefix the variable name with 'export' then 'set' wont display it?

markush 06-01-2013 03:49 AM

Hi,

if you want to use VISUAL or EDITOR as environment-variables, you should in your /etc/profile (or in local .profile or .bashrc) do the following
Code:

VISUAL=/usr/bin/vim
EDITOR=/usr/bin/vim
export VISUAL
export EDITOR

this will work in most cases.

Markus

stf92 06-01-2013 03:53 AM

Thank you.

Diantre 06-01-2013 04:37 AM

Quote:

Originally Posted by stf92 (Post 4963304)
Are not the variables output by the set command without arguments all of them environment variables? You mean that if, in /etc/profile, I don't prefix the variable name with 'export' then 'set' wont display it?

No and no.

I didn't mention "set" nor /etc/profile. I don't "mean" anything. I only answered your previous question about why 'less' wasn't seeing a shell variable. RTFM.

stf92 06-01-2013 06:04 AM

I've read the F manual, as you say, 13467 times and still can't make any sense of it. On the other hand, I don't have to read any manual if I want to ask a question. Are you some busy developer that answers questions as an act of charity? Besides, I did not ask you to answer any question. If you want to respond, that's your business.


All times are GMT -5. The time now is 09:56 AM.