2005/02/10 ex

Ex is the non-visual mode of vi, the mode that you are in when you type ":". You can enter this mode semi-permanently by typing "gQ" (return to visual mode with "vi").

Why would you want to do such a thing? Well, because if you are going to do a bunch of ex mode commands in a row, and only care about seeing the results, this is the way to do it. No more ":" to type, no waiting for the screen to redraw. Ex is "line at a time" mode: if you search for a pattern, only the first matching line displays. Press ENTER, and you see the line below it. Let's look at an example with this file:


abc def ghi
ghi abc abc
def lmn opq
abcdefghi
ghi abc abc
def lmn opq
abc def ghi
abcdefghi
ghi abc abc
def lmn opq
 

I want to go to each line with "abc", but not "abcdef", and possibly make some changes. Here's what it looks like after typing "Gq" and entering commands:

(enter vi, type gQ)
Entering Ex mode.  Type "visual" to go to Normal mode.
:set number

:/abc[^a-z]\|abc$
      2 ghi abc abc
:/
      5 ghi abc abc
:/
      7 abc def ghi
:/
      9 ghi abc abc
:/
      1 abc def ghi
:set nonumber

:vi
(screen clears)
abc def ghi 
ghi abc abc 
def lmn opq 
abcdefghi  
ghi abc abc 
def lmn opq 
abc def ghi 
abcdefghi  
ghi abc abc 
def lmn opq 

Bruce Garlock reminded me that /\<abc\> also finds abc in the same way.

Ex mode is also useful when you have sub-standard terminal emulation and the screen gets messed up because of it. Having lines displayed one at a time can be much less confusing.

Got something to add? Send me email.





(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> ex (non visual vi)




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

privacy policy