- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- vi command ?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 03:21 AM
11-01-2005 03:21 AM
Just wanted to ask (2) questions about using vi :
1) how do you delete text from current line to end of file ?
2) from command line, how do you change/substitute a string throughout the entire line :
ex:
command # 1
# mkdir foo1 foo2 foo3 foo4
I want pull this same command from history
( esc k ) and substitute "foo" with "toe"
so it executes :
# mkdir toe1 toe2 toe3 toe4
please advise, Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 03:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 04:39 AM
11-01-2005 04:39 AM
Re: vi command ?
from the command line? Is there an example to use after the "esc k" ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 04:43 AM
11-01-2005 04:43 AM
Re: vi command ?
1,$s/foo/toe/g
How do I use this from the command line ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 05:29 AM
11-01-2005 05:29 AM
Re: vi command ?
Run this command and you will see output on screen. Can redirect this output to a file
cat $file | sed s/foo/toe/g > $file.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 05:42 AM
11-01-2005 05:42 AM
Re: vi command ?
the history to pull up previous cmd, and substitute to "string1" w/ "string2" on the command line. I still might not be clear, but as an example :
command1
# mkdir foo1 foo2 foo3 foo3
# "esc k" returns
# mkdir foo1 foo2 foo3 foo3
When the history returns the previous command
above, that's where I want to substitute
"foo" w/ "toe" ? I'm trying to substitute directly from cmd line, and not output to a file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 05:50 AM
11-01-2005 05:50 AM
Re: vi command ?
If you have the 'esc-k' functionality, the editing functionality is probably with vi (this is a guess). So bring the history, mkdir toe1 toe2 toe3 toe4, the cursor will be on the 'm' of the mkdir. Use the 'w' key to advance 1 word, 'cw' to change word from foo to toe, hit the esc key to go back into command mode, 'w' to advance to next word, 'cw' to change word from foo1 to toe1, etc...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 05:53 AM
11-01-2005 05:53 AM
Re: vi command ?
LAST LINE MODE
/PATTERN search forward
?PATTERN search backwards
/ or ? or n repeat last search
N reverse last search
:w write buffer to disk
:w NEWFILE write buffer to NEWFILE
:w >> FILE append buffer to FILE
:w! FILE force a write to FILE
:wq write then quit
:q quit
:q! quit without writing
:f show file name and line #
:cd DIRECTORY change DIRECTORY
:r read file into buffer
:r FILE read named FILE
:e edit
:e! discard buffer and edit
:e FILE edit a FILE
:e # pop between files
:s/OLD/NEW/ current line sub. 1st
:s/OLD/NEW/g current line sub. all
:1,7s/OLD/NEW lines 1-7 sub. all
:%s/OLD/NEW all lines sub. 1st
:%s/OLD/NEW/g all lines sub. all
:%s/^/PATTERN /g insert PATTERN at beginning of line all lines
:%s/$/ PATTERN/g insert PATTERN at end of all lines
:set nu show line numbers
:set nonu hide line numbers
:set sm enable matching ()s
:set nosm disable matching ()s
$ end of line
^ beginning of line
/ search
:%s/.$// remove last character on every line
INSERT MODE
a append after cursor
A append at end of line
i insert before cursor
I insert at start of line
o open a line below cursor
O open a line above cursor
cw change word at cursor
c#w change # of words
C change text to end of line
r replace a character
R replace text unti
#a
#a
#i
#I
^w erase last word
COMMAND MODE
h move cursor left
l move cursor right
j move cursor down one line
k move cursor up one line
G go to end of file
#G go to line #
H go to top of screen
M go to middle of screen
L go to bottom of screen
w move cursor forward one word
b move cursor back one word
#w move cursor forward # words
#b move cursor back # words
x delete character
dd delete line
#dd delete # lines
dw delete word
#dw delete # words
d$ delete to end of line
P paste before cursor
p paste after cursor
"vp paste buffer v after cursor
xp transpose two characters
Y yank a line
#Y yank # lines
"v#Y yank # lines to buffer v
. repeat last command
u undo
CHANGE A VALUE THROUGHT A FILE
:g/$oldpattern/s//$newpattern/g
this was for changing DNS values in the db.* files
:g/SOA/s/$oldpattern/$newpattern/g
The 'g' at the beginning and end of the command indicate that the changes are to occur horizontally and vertically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 05:55 AM
11-01-2005 05:55 AM
Re: vi command ?
trying.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2005 02:24 PM
11-01-2005 02:24 PM
Re: vi command ?
Under bash, the following command will do the substitution you seek:
$(echo !mkdir | sed -e "s/foo/toe/g")
For example:
# mkdir foo1 foo2 foo3
# ls
foo1 foo2 foo3
# $(echo !mkdir | sed -e "s/foo/toe/g")
$(echo mkdir foo1 foo2 foo3 | sed -e "s/foo/toe/g")
# ls
foo1 foo2 foo3 toe1 toe2 toe3
I'm not sure how to suppress the echo of that command line to the screen though (if it even matters) redirecting to >/dev/null didn't seem to work.
-Jared
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2005 01:55 AM
11-02-2005 01:55 AM
Re: vi command ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2005 08:25 AM
11-04-2005 08:25 AM
Re: vi command ?
(This assumes you have "set -o vi" set, which it sound like you do.)
You can then use your typical editing commands to modify the shell command or script - this is VERY handy for developing small shell scripts, by the way.
so:
# mkdir foo1 foo2 foo3 foo4
( esc k )
v
:s/foo/toe/g
ZZ --- to write, quit, execute command
Cheers,
Vince
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2005 08:32 AM
11-04-2005 08:32 AM
Re: vi command ?
Thanks.......... :>) !