Solved

vi editor command - delete a column.

Posted on 2015-02-20
4
361 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

838 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