Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 627
  • Last Modified:

vi editor command - delete a column.

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
Rambl
Asked:
Rambl
  • 2
2 Solutions
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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
 
woolmilkporcCommented:
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
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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
 
RamblAuthor Commented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now