vi editor - ctrl+w not working

Hi All,

I am new to FreeBSD. I have just started to learn about the vi editor from a book. It has a command ctrl+w to delete the last typed word. It does not work for me. However it works fine on another Linux machine of a friend. What am I missing? Is there some keyboard mapping that needs to be done? Thanks in advance.
 
Hi,

as far as I know FreeBSD is deployed by default with pure VI editor whilst Linux distributions uses VIM and VI is just an alias to this.
By default VI is very limited in functionality. To get better overview just use

man vi

and check what is supported by ti. If you wish you can install VIM on FreeBSD but I would not recommend as it does have vulnerabilities reported by pkg audit

Regards,
Krzysztof
 
On a lot of Linux distributions vi(1) is actually vim(1). On FreeBSD vi(1) is actually nvi. So there could be various implementation differences.

That said, ctrl-w on FreeBSD's nvi(1) works as expected. The only noticable difference seems to be that on Linux' vi(1) the characters are visibly removed, on FreeBSD only the cursor moves (but the characters are deleted nonetheless).
 
If you wish you can install VIM on FreeBSD but I would not recommend as it does have vulnerabilities reported by pkg-audit(8)
I don't know how old your system is but the last issue with vim(1) stems from 2016: http://www.vuxml.org/freebsd/pkg-vim.html
Maybe you should update.

Code:
root@c1:~# pkg version -vR | grep vim
vim-console-8.1.0342               =   up-to-date with remote
root@c1:~# pkg audit
0 problem(s) in the installed packages found.
root@c1:~#
 
Perhaps also look into editors/vim-tiny (without all the gvim / X11 cruft). Less moving bits means less bugs / security issues ;)

I imagine the only potential security issues with Vim these days involve the vim-server stuff to automate it with scripts (I think it uses a network socket). Luckily vim-tiny is vim without that kind of thing compiled in.
 
Thanks all. I will try out the stuff given in each of the replies once I reach home. Right now I am just amazed to get so much help within just a couple of hours of posting the question. u guys r awesome !!
 
SirDice thank you for your spot light on that
I don't know how old your system is
I have 10.4 and 11.2 versions but when I checked the VIM version, it appeared outdated, that's why I can see vulnerability :/

Code:
vim-lite-7.4.979 is vulnerable:
vim -- arbitrary command execution
CVE: CVE-2016-1248
WWW: https://vuxml.FreeBSD.org/freebsd/c11629d3-c8ad-11e6-ae1b-002590263bf5.html

Now it is clear why. I am going to update this soon.

Regards,
Krzysztof
 
I have 10.4 and 11.2 versions but when I checked the VIM version, it appeared outdated, that's why I can see vulnerability
vim-lite was renamed to vim-console quite some time ago. The -lite was a bit of a misnomer.
 
It has a command ctrl+w to delete the last typed word
Till now I used vi in very limited way, my main editor is emacs.

One of the first things I wanted to learn, is how to deal with many files, then I learned that one can open many
"screens" in the same window, this is also one of the first things treated here:


Well, if you have many screens in a window, the command for changing screen is: ^W

In other words: ^W exists, but it is not for deleting the last typed word as the OP said.

I wonder, that no one in this thread mentioned it.

And could the command the OP wanted not be something like u or dB, depending of what he did and where is the cursor ?

Is it, that few people use vi? Or people use vi with tmux / screen?

I think there is someone here that bloats more emacs running it with tmux, although emacs can open many windows,
run a shell in a window and may run as daemon.
 
Then my question should be if someone is using nvi?

I just ggoogled, ^W in vim seems not to be something very different:


Do few people use vi? There is a whole thread on the favourite text editor:

 
I think there is someone here that bloats more emacs running it with tmux, although emacs can open many windows,
run a shell in a window and may run as daemon.
I didn't see the point of tmux because I thought emacs windows could do the same, but after trying it, I realise I was very mistaken.
 
I didn't see the point of tmux because I thought emacs windows could do the same, but after trying it, I realise I was very mistaken.
What is the problem with "M-x shell" in emacs? Well, it seems one cannot run vi from there.

But why is this necessary? By every use of emacs?
 
Old school vi to delete last word while in insert mode:

Code:
<esc>    <--- command mode
b        <--- jump to the beginning of the previous word or current word if the cursor is within a word
dw       <--- delete word

or

<esc>
db
 
Classical vi is a bit more restricted than vim, I tend to mostly use vim nowadays.
In vim you have many deletion options, obtained by combining the 'd' delete command with one of the motion commands, see https://vimdoc.sourceforge.net/htmldoc/motion.html#motion.txt

So...
  1. d<leftArrow> will delete current and left character
  2. d$ will delete from current position to end of line
  3. d^ will delete from current backward to first non-white-space character
  4. d0 will delete from current backward to beginning of line
  5. db deletes current to beginning of current word
  6. de delete current to end of current word
  7. dw delete current to end of whitespace following end of current word
I got into the habit of using 'dbx' (which is easy to remember since it's the name of an audio processing system!), so you get to the end of the word, hit esc to get to command mode, then 'db' deletes back to the start of the word, but you need the 'x' to delete the final character. Or 'bdw' is another equivalent way. Once you've done it a few times it becomes automatic and you do it without thinking.
 
Old school vi to delete last word while in insert mode:
So much flexibility. To delete an arbitrary number of words
Code:
<esc>    <--- command mode
mm    <--- set marker 'm'
bbb    <--- Move back to the beginning of the words I want to delete (i.e 3 words)
d`m    <--- delete to marker 'm'

  1. dw delete current to end of whitespace following end of current word
Quite a nice one is i.e d2w (to delete i.e 2 words), d3w (to delete 3) etc.
 
The word deleted is the last word entered before returning to command mode in that input mode.
Previously entered words will not be deleted.
ah, yeah, your're right... egg on face, hahaha; for some reason... I never do that! I will train myself to start doing it now...
 
Another backwards delete that can be very useful is to search backwards for a specific character and delete everything up to and including that character.

So if you have a line like

"iasdfasdf as asdfasdfG asdfasdf dfasdfasdf hasdfasdf"

and you issue the command "dFG"
it will delete it back to

"iasdfasdf as asdfasdff"

Of course you still need an 'x' to delete the pesky character that was under the cursor at the end of the line when you issued the command, so you really need to say "dFGx".
If you want to preserve the 'G' in this case, change the 'F' command to a 'T'.

It works going forwards too, if you change the 'F' to 'f'. Great editor.
 
Classical vi is a bit more restricted than vim, I tend to mostly use vim nowadays.
In vim you have many deletion options, obtained by combining the 'd' delete command with one of the motion commands, see https://vimdoc.sourceforge.net/htmldoc/motion.html#motion.txt

So...
  1. d<leftArrow> will delete current and left character
  2. d$ will delete from current position to end of line
  3. d^ will delete from current backward to first non-white-space character
  4. d0 will delete from current backward to beginning of line
  5. db deletes current to beginning of current word
  6. de delete current to end of current word
  7. dw delete current to end of whitespace following end of current word
But ironically all these examples date back to the original vi. (Except maybe the first one, but dl and the complementary dh would work. However, nvi from the base system only deletes one character - as one would expect. I haven't had the need to install vim for a long time, so I can't confirm if they really broke compatibility there.)
 
Back
Top