Solved

vi editor command - delete a column.

Posted on 2015-02-20
4
389 Views
Last Modified: 2015-02-20
I know vi relatively well.

dd - deletes a line
5 dd - deletes 5 lines.

How do you delete a singe character column? ...or  5 character columns, all the way to the bottom of the vi document?
0
Comment
Question by:Rambl
  • 2
4 Comments
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 250 total points
ID: 40621416
You can use the block mode of vi, use <ctrl>-v to enter that mode, select text by moving cursor (to the right). Use G to go to end of the file and press d to delete your column. Leave block mode using <esc>
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 40621429
As far as I know, vi cannot do that, but vim can.
In most Linux'es "vi" is in fact "vim".

- Position the cursor at the start column and hit <Ctrl><v>
- Move the cursor to the end column. The block will be highlighted.
- Move the cursor down to mark a rectangle to operate upon.
EDIT: "G" does not work here (at least not for me) because it jumps to the first column of the last line.
- Hit the key corresponding to the desired action, e. g. "d" for delete.

The above is called "visual block mode" in vim.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40621463
vim - yes, the default 'vi' on most Linux systems.

@Rambi: if you do "vi --version", do you see something like:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 10 2013 03:57:45)
...

If that's so then you have vim (with an alias named vi) and you can use the visual mode.
0
 

Author Closing Comment

by:Rambl
ID: 40621494
which vi
/bin/vi

which vim
usr/bin/vim

-rwxr-xr-x  1 root root  629032 Jul 10  2012 vi
-rwxr-xr-x  1 root root    2828960 Jul 10  2012 vim

when I run vi, it doesn't allow me to do a ctrl-v (visual block)
when I run vim, it does

what's odd, is if I run:
/usr/bin/vim --version
/bin/vi --version

They seem to be the same version.

Perhaps vi is using the same config files the vim is using, but it still functions like the old vi. Maybe it's running "vim" in some kind of "vi" mode.

I just thought that was interesting.

Anyway, thanks for the help. ctrl-v in vim accomplished what I wanted.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question