LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   using backspace or delete in vi (https://www.linuxquestions.org/questions/slackware-14/using-backspace-or-delete-in-vi-132091/)

Mugatu 01-06-2004 12:22 PM

using backspace or delete in vi
 
i'm used to using vi in other distros. how do i use the backspace or delete key when using vi in slackware 9.1? when i press them nothing happens at all. is there a better CLI editor i should be using?

trickykid 01-06-2004 12:45 PM

Use or try these while in command mode:

x - deletes one character at a time
dd - deletes the whole current line

gnashley 01-06-2004 02:42 PM

You might try using the text editor 'joe'.
I use vi all the time as it's fast and present in all distros in some form or another. In Slackware it is actually 'elvis' in others maybe something else which is wha they don' always act the same. Something I only found out recently is that vi will render html files as well!
'x' deletes characters under the cursor and to the right of the cursor(one at a time)

Kovacs 01-06-2004 06:35 PM

Personally I link vim rather than elvis to vi. As root:
rm /usr/bin/vi
ln -s /usr/bin/vim /usr/bin/vi

Then as your regular user make a file called .vimrc in your home directory, with these contents:

set backspace=indent,eol,start
fixdel

And you can now use backspace when you run vi (which is now really vim).

In my .vimrc I also have:
syntax enable
set number
set autoindent
set tabstop=4

which enables syntax highlighting, shows line numbers, autoindents your code and sets the tab length to 4 characters. There are tons of other options, have a look on the vim website.

There is also an integrated tutorial in vim, it takes about 30 mins and is well worth it to introduce you to some of vim's less than intuitive features... it's a great editor once you get the hang of it.

gnashley 01-07-2004 05:24 AM

Yes vim is also nice. Maybe it was 'jed' I meant to suggest instead of joe. I haven't used them, just know that thex are there in Slack 9.1. One other trick, though for vi- it can be called from within 'less'. This is nice for viewing and then editing files, since if you make a typo in vi, a file will be created with the name you typed. So instead of directly calling a file in vi: vi /etc/X11/XF86Config, I call it with 'less':
less /etc/X11/XF86Config then when i find the section I want to edit just type 'vi' (within less). After exiting vi witn ':q!' or ':wq' it returns you to 'less'. a much safer way to quickly edit files. You have posted are probably familiar with these tricks, but I post them for the benefit of others who may not know.

Mugatu 01-07-2004 07:45 AM

joe worked, and at least it will let me use my backspace and delete keys :D i'll give vim a try as well. thanx for all the input

malo_umoran 01-07-2004 09:51 AM

Re: using backspace or delete in vi
 
Quote:

Originally posted by Mugatu
i'm used to using vi in other distros. how do i use the backspace or delete key when using vi in slackware 9.1? when i press them nothing happens at all. is there a better CLI editor i should be using?

backspace or delete are not standard vi commands.

* ctrl+x deletes char
* d$ deletes rest of the line
* dG deletes rest of the file
* dd deletes line and puts the line in the clipboard
* 5dd deletes line + 4 next lines

etc.

M.

ringwraith 01-07-2004 11:42 AM

I think the most userfriendly of the console based text editors is pico or nano. Just be sure to use pico -w on the config files. I use both it and elvis for all my text editing needs :)

Astro 01-07-2004 03:13 PM

I grabbed a very very nice .vimrc file from somewhere and I can't remember the site or I would post it. It seems to be a problem with terminal emulation as to the backspace problem... for instance.... in console you can backspace fine, however in say Gnome-terminal it doesn't work so well where as in rxvt it works fine. Not sure how to correct this though, and I havn't had much time, but theres my $0.02

Kovacs 01-07-2004 07:42 PM

You should be able to fix that with these two lines in .vimrc:

set backspace=indent,eol,start
fixdel

slackwaresux 10-20-2004 02:46 PM

Quote:

Originally posted by Kovacs
Personally I link vim rather than elvis to vi. As root:
rm /usr/bin/vi
ln -s /usr/bin/vim /usr/bin/vi

Then as your regular user make a file called .vimrc in your home directory, with these contents:

set backspace=indent,eol,start
fixdel

And you can now use backspace when you run vi (which is now really vim).

In my .vimrc I also have:
syntax enable
set number
set autoindent
set tabstop=4

which enables syntax highlighting, shows line numbers, autoindents your code and sets the tab length to 4 characters. There are tons of other options, have a look on the vim website.

There is also an integrated tutorial in vim, it takes about 30 mins and is well worth it to introduce you to some of vim's less than intuitive features... it's a great editor once you get the hang of it.


After hours of frustration, that worked!!! You're a genius, thanks man!!! :D

slackwaresux 10-20-2004 05:28 PM

Actually your solution worked but then I had to start from scratch, when I created the .vimrc file, now the "delete" key does not work. Could you explain the reason why?

Thanks for the help.

levicc00123 10-20-2004 09:04 PM

Here's what did the trick for me:

Code:

:set nocp
:map <BS> ^H
set backspace=indent,eol,start
fixdel
:syntax enable
:set number
:set autoindent
:set tabstop=4


gbonvehi 10-21-2004 12:01 AM

What I would recommend is to copy /usr/share/vim/vim63/vimrc_sample.vim to ~/.vimrc
That will give you all nice things :)

stf92 06-01-2018 04:16 PM

A question: what has .vimrc to do with vi?

Didier Spaier 06-01-2018 06:17 PM

Quote:

Originally Posted by stf92 (Post 5862314)
A question: what has .vimrc to do with vi?

Did you notice that the previous post of this thread is more than 13 years old?

Furthermore the answer has been given in post #4, more that 14 years ago!

stf92 06-01-2018 06:44 PM

So?

enorbet 06-01-2018 06:56 PM

Although I started with Slackware v9.0 and began using vi then, I can't recall how it functioned back then in terms of the Delete and Backspace keys. That said, since v12 iirc the stock vim that comes with each release has very handy default configs from my POV. I can delete a character or a series of characters with the Delete key without ever having invoked "i" insert mode and then save that with the ordinary ":wq" command, without ever having entered insert mode. I know that's only one keystroke and a very minor issue but the point is Delete key does delete and rather handily in modern vim. Perhaps there is a way to utilize a more modern version in your older system. It certainly would be trivial to try.

Edit : NecroOOPS!

stf92 06-01-2018 07:42 PM

I say vi's default behavior in what respects to the backspace key is weird. The name of the key implies its function: go back one space. But vi does not seem to agree. If you edit a new file (with vi), type some letters (except Enter), save and quit. Then reedit it and press A (that will send the cursor to the end of the line) and you now press the backspace key, you'll see nothing happens! It is this behavior that keeps people away from vi and throus them in the arms of vim.

I have read many posts regarding this strange default behavior of the backspace key but none of them has ever been of any use to me. I think it would be intelligent on the part of the developers (if vi is still being maintained) to make the default behavior of the backspace key that which it has in vim (which on the other hand is logical) and, if someone wants to make it do those strange things, then write the appropriate line in its config file which, by the way, I don't know which it is (I mean, has vi a cofiguration file like .vimrc in vim?).

One thing is still odder. I have vi installed by default in Debian 9. Then I installed vim and wrote this ~/.bashrc:
Code:

semoi@debian:~$ cat .vimrc
set backspace=indent,eol,start
fixdel
semoi@debian:~$

Now I ran vi and found the backspace key behaved as in vim (normal behavior). Excelent I said, and uninstalled vim. But then vi reverted to its old behavior. Does this mean when I installed vim vi became a link to vim?

volkerdi 06-01-2018 09:46 PM

Quote:

Originally Posted by stf92 (Post 5862364)
I say vi's default behavior in what respects to the backspace key is weird. The name of the key implies its function: go back one space. But vi does not seem to agree. If you edit a new file (with vi), type some letters (except Enter), save and quit. Then reedit it and press A (that will send the cursor to the end of the line) and you now press the backspace key, you'll see nothing happens! It is this behavior that keeps people away from vi and throus them in the arms of vim.

You've put vi (elvis) into insert mode. Insert mode will not delete previously existing text. You could hit Esc, and then start hitting 'x' to delete characters.

Quote:

I have read many posts regarding this strange default behavior of the backspace key but none of them has ever been of any use to me. I think it would be intelligent on the part of the developers (if vi is still being maintained) to make the default behavior of the backspace key that which it has in vim (which on the other hand is logical) and, if someone wants to make it do those strange things, then write the appropriate line in its config file which, by the way, I don't know which it is (I mean, has vi a cofiguration file like .vimrc in vim?).
Conversely, I find vim to behave strangely compared with the classic vi that I used on Unix. Elvis is pretty close to that, but I suppose we could have nvi, which is actually derived from what was used back then.

A real vi user does not need the cursor keys or the backspace key anyway.

Quote:

One thing is still odder. I have vi installed by default in Debian 9. Then I installed vim and wrote this ~/.bashrc:
Code:

semoi@debian:~$ cat .vimrc
set backspace=indent,eol,start
fixdel
semoi@debian:~$

Now I ran vi and found the backspace key behaved as in vim (normal behavior). Excelent I said, and uninstalled vim. But then vi reverted to its old behavior. Does this mean when I installed vim vi became a link to vim?
vi might be a symlink to vim on Debian. In fact, that would not surprise me.

stf92 06-02-2018 03:16 PM

Quote:

Originally Posted by volkerdi (Post 5862395)
You've put vi (elvis) into insert mode. Insert mode will not delete previously existing text. You could hit Esc, and then start hitting 'x' to delete characters.

But if I want to delete 15 chars behind the cursor I should hit 'x' 15 times to erase them. In vim (in the default setting) I only have to hit the backspace key once and hold it down until all chars have been deleted. I think that's economy.

Quote:


vi might be a symlink to vim on Debian. In fact, that would not surprise me.
In fact what makes the behavior of vi to emulate that of vim is this (if you have vim installed):
Code:

root@debian:~# whereis vi
vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz
root@debian:~# ls -l /usr/bin/vi
lrwxrwxrwx 1 root root 20 May 30 14:52 /usr/bin/vi -> /etc/alternatives/vi
root@debian:~# ls -l /etc/alternatives/vi
lrwxrwxrwx 1 root root 18 Jun  2 16:52 /etc/alternatives/vi -> /usr/bin/vim.basic
root@debian:~#

So it seems it is vim.basic who is being executed!

volkerdi 06-02-2018 03:27 PM

Quote:

Originally Posted by stf92 (Post 5862633)
But if I want to delete 15 chars behind the cursor I should hit 'x' 15 times to erase them. In vim (in the default setting) I only have to hit the backspace key once and hold it down until all chars have been deleted. I think that's economy.

You could hit: 15x

Quote:

In fact what makes the behavior of vi to emulate that of vim is this (if you have vim installed):
Code:

root@debian:~# whereis vi
vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz
root@debian:~# ls -l /usr/bin/vi
lrwxrwxrwx 1 root root 20 May 30 14:52 /usr/bin/vi -> /etc/alternatives/vi
root@debian:~# ls -l /etc/alternatives/vi
lrwxrwxrwx 1 root root 18 Jun  2 16:52 /etc/alternatives/vi -> /usr/bin/vim.basic
root@debian:~#

So it seems it is vim.basic who is being executed!
The theory was correct, then.

montagdude 06-02-2018 04:43 PM

Quote:

Originally Posted by stf92 (Post 5862633)
But if I want to delete 15 chars behind the cursor I should hit 'x' 15 times to erase them. In vim (in the default setting) I only have to hit the backspace key once and hold it down until all chars have been deleted. I think that's economy.



In fact what makes the behavior of vi to emulate that of vim is this (if you have vim installed):
Code:

root@debian:~# whereis vi
vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz
root@debian:~# ls -l /usr/bin/vi
lrwxrwxrwx 1 root root 20 May 30 14:52 /usr/bin/vi -> /etc/alternatives/vi
root@debian:~# ls -l /etc/alternatives/vi
lrwxrwxrwx 1 root root 18 Jun  2 16:52 /etc/alternatives/vi -> /usr/bin/vim.basic
root@debian:~#

So it seems it is vim.basic who is being executed!

Not to be elitist or anything, but if you are wanting to press and hold backspace to delete a bunch of characters in vi/vim, you are doing it wrong. I recommend you learn the proper keyboard shortcuts. You will be much more productive.

(As far as being elitist is concerned, I'm not that hardcore. I use vim instead of elvis.)

stf92 06-02-2018 05:10 PM

But what if you make a mistake while typing and type a j instead of a k? You are in insert mode. OK. You have not to exit insert mode. You just hit one key: backspace!

montagdude 06-02-2018 07:52 PM

Quote:

Originally Posted by stf92 (Post 5862657)
But what if you make a mistake while typing and type a j instead of a k? You are in insert mode. OK. You have not to exit insert mode. You just hit one key: backspace!

Well yeah, but we were talking about deleting 15 characters, not 1.

Petri Kaukasoina 06-03-2018 03:19 AM

Quote:

Originally Posted by stf92 (Post 5862633)
But if I want to delete 15 chars behind the cursor I should hit 'x' 15 times to erase them. In vim (in the default setting) I only have to hit the backspace key once and hold it down until all chars have been deleted. I think that's economy.

Or hit 'x' once and hold it down until all chars have been deleted.


All times are GMT -5. The time now is 05:54 PM.