Map Editing even easier with VIM

thamis

King of Kish
Joined
Jan 21, 2002
Messages
1,583
Outline

This article covers how to do the following things to a WBS file:
- remove all TeamReveals with a few keystrokes
- remove all Units with a few keystrokes
- remove all Cities with a few keystrokes

There are many more things that you can do. Please comment here if you want to do something and you aren't sure how, or if you've found an even quicker way!

Here are all the keystrokes you have to press without explanations. You can be stupid as a monkey, simply load the file and press the keys.

VIM

Ok, after I have written my tutorial on how to make clean maps without causing WorldBuilder to mess stuff up, here's a tip on how to vastly improve your editing speed with one of the most powerful text editors, VIM. You can download VIM here. It's free!

The great thing about VIM: It's very powerful. You can make yourself macros which are very very very helpful if you want to edit a certain thing in your map, maybe over and over again.

The bad thing about VIM: It's pretty damn complex. I haven't mastered it yet, far from it. But I've found some pretty nifty ways to help editing WBS files, and I'll explain them for you all here!

First of all, VIM has three editing modes: NORMAL (what you get when you start VIM, you can't actually write anything into the text file), INSERT (works like the normal text editor), REPLACE (everything you type replaces existing text).

The Modes

NORMAL: You get this mode when VIM comes up. In this mode, you can use all the keyboard shortcuts of VIM. We'll use this mode a lot. If you're in any other mode, pressing ESC gets you back to normal mode.

INSERT & REPLACE: Well, pretty much like any text editor. Enter these modes by pressing the INSERT key on your keyboard (once for insert, twice for replace). Press ESC to get back to normal.

VISUAL: You get there by pressing either "v" or "V". This mode is good for selecting lines of text. If you press "V" (SHIFT+V) you can only select full lines. We'll need that later.

Commands

First off, let me tell you a few useful commands. They work in NORMAL mode, and when you type them you'll see them in the bottom line. Some of them require enter to be executed, others don't.

Code:
/thetext [ENTER] = Searches for all occurrences of "thetext" in your text. This is case sensitive!

/ [ENTER] = Repeats the last search, or goes to the next occurrence in the text.

dd = Deletes the line you're on

q# = Starts recording a macro, where # is a character (0-9, a-z).
q = Finishes recording a macro

@# = Execute macro named #

Now, the cool thing about VIM is that you can tell the program to repeat a certain command an unlimited number of times! So if you type 6dd, it will delete 6 lines - the line your cursor is on and the 5 lines after it. You can also execute a macro several times. 1000@1 will execute macro 1 a thousand times. Remember, this only works in NORMAL mode (press ESC to get there).

Ok, so let's say you have a map that you saved in WorldBuilder, and there are cities, units, and revealed plots saved in there, none of which you want to have. How can we remove them? Let's start with revealed plots, that's easiest.

Remove All Revealed Plots

First, go to the top of the document (CRTL+HOME will get you there). We will now create a macro, let's call it "t" for TeamReveal. Enter NORMAL mode. Type:

Code:
qt

No pressing ENTER needed. You'll see in the bottom left that it now says "recording". Now let's search for the first instance of TeamReveal.

Code:
/TeamReveal

Press Enter. Remember that the search function is case sensitive. If you type all lowercase, it won't find anything. You'll get a yellow marked TeamReveal. Now type

Code:
dd

This will remove the whole line that says TeamReveal. This way, we can remove ALL TeamReveals, no matter what team number they refer to.

Now stop recording. Press

Code:
q

Ok, we've got Macro 1. What it does: Find a line that says TeamReveal. Delete that line. Since we don't know how many plots are revealed, let's do that 1000 times. This may or may not remove all team reveals. If there are any left, we can simply do it another 1000 times. Go back to the top of the document. Type:

Code:
1000@t

No pressing ENTER required. You will now see the editor quickly go through the text, removing all TeamReveals. If it finished through the document and there were less than 1000 instances, you'll get a red error message at the bottom of the document, stating that there are no TeamReveals left. Done! If you don't get the error message and there are instances left, simply execute the macro another 1000 times: 1000@t

Remove All Units

This is very similar. Every unit is marked with BeginUnit and EndUnit (which comes 5 lines later).

Start recording a macro, we'll call it "u" for units:

Code:
qu

Don't press enter. Type

Code:
/BeginUnit

Press ENTER. The first instance of BeginUnit is now marked yellow. Type

Code:
V

Yes, that's SHIFT+V! Don't press enter.

Code:
/EndUnit

ENTER. Now everything from BeginUnit to EndUnit should be selected. To delete it, press

Code:
d

End recording the macro:

Code:
q

Then go back to the top of the document and execute the macro 1000 times:

Code:
1000@u

Again, if all units are removed you'll get an error message.

Remove All Cities

Works very similarly. The only problem is that cities can have a different number of lines (unlike units, which always are 6 lines). I'll quickly take you through it:

Code:
qc

Starts recording the macro.

Code:
/BeginCity

ENTER.

Code:
V

Yes, that's SHIFT-V, which gets you into VISUAL mode, line select.

Code:
/EndCity

ENTER. Selects all text from BeginCity to EndCity.

Code:
d

No enter. Deletes the selected text.

Code:
q

No enter. Stops recording the macro. Go to the top of the document (CRTL+HOME).

Code:
1000@c

No enter. Executes the macro 1000 times.

From Now On...

You should be able simply to type 1000@t to delete all TeamReveals, 1000@u to delete all units, and 1000@c to delete all cities. VIM should save these macros until you re-define them with something different.
 
Here are the instructions in simple command form, without explanation. Do not press enter unless it says here. Note that all this is case sensitive, so don't press "v" when it says "V"!

[ENTER] means that you have to press enter on the keyboard, [CRTL+HOME] means that you have to press these two keys on the keyboard at the same time.

Remember that you only have to do all those keystrokes once. After having recorded the macro, you only have to execute the last line: 1000@c, for example, to remove all cities.

Remove all TeamRevealed
Code:
qt
/TeamReveal [ENTER]
dd
q
[CRTL+HOME]
1000@t

Remove all Units
Code:
qu
/BeginUnit [ENTER]
V
/EndUnit [ENTER]
d
q
[CRTL+HOME]
1000@u

Remove all Cities
Code:
qc
/BeginCity [ENTER]
V
/EndCity [ENTER]
d
q
[CRTL+HOME]
1000@c

Remove all Improvements
Code:
qi
/ImprovementType [ENTER]
dd
q
[CRTL+HOME]
1000@i

Remove all instances of a specific Improvement, aluminum for example
Code:
qa
/BONUS_ALUMINUM [ENTER]
dd
q
[CRTL+HOME]
1000@a
 
To remove something globally, instead of n number of times with a macro, use:
Code:
:% s/find/replace/

I don't remember off the top of my head how to remove a line instead of just blanking it out, however.
 
You can use this to find and delete lines:

Code:
:g/pattern/d

The :g command performs global Ex commands on matching lines, in this case a 'd' for delete.

From the VIM docs: :help :g
 
You may want to try these commands as well:

Code:
" Remove all TeamRevealed
:g/TeamReveal/d

" Remove all Units
:g/BeginUnit/:.,/EndUnit/d

" Remove All Cities
:g/BeginCity/:.,/EndCity/d

" Remove All Improvements
:g/ImprovementType/d

" Remove all instances of a specific Improvement, aluminum for example
:g/BONUS_ALUMINUM/d

The ':g/pattern1/:.,/pattern2/d' command breaks down to "everywhere you find /pattern1/, delete from there through the next line containing /pattern2/ ".
 
This is the greatest program every developed.....<g>. It saves HOURS of time editing those darned WBS files. Thanks for the tutorial on using it.
 
I think it's funny that I've used vi for years on unix systems and never messed with macros, but now use them for editing a windows game.
 
To remove case sensitivity enter this:
:set ic

Or better yet add this to your _vimrc file so it's always set. And if you need case sensitivity for some crazy reason:
:set noic


Marks are also really handy. To use them, press "m" followed by a letter. For example "ma" sets mark "a" on the current line. Operations can be performed between 2 marks. For example, to write a section of the buffer to a new file:
ma
<scroll down bunch of lines>
mb

:'a,'b w newfile
newfile contains only the lines starting at mark "a" and ending at mark "b".

or to perform some edit only on that section:
:'a,'b s/boo boo/correction/
 
ChiefStupidName said:
To remove something globally, instead of n number of times with a macro, use:
Code:
:% s/find/replace/
I don't remember off the top of my head how to remove a line instead of just blanking it out, however.
It's:
Code:
dd

I just create a function in my _vimrc file which uses dd with the s// function, but there's probably a simpler way.
 
I downloaded VIM and got a map open with it. I followed the instructions for removing units and team reveals. But when I went to save it the game did not recognize its existance (it didn't appear in the list of selectable maps). The saved (new) map is called a "civ4worldbuilder" file, but has a different icon. I tried opening it by double clicking it and selecting civ4 to open the file. No go, it's not on the list.

I'm trying to get rid of all of the existing civs on the map and substitute custom civs of my own.

Thanks for any help

Freddy
 
Back
Top Bottom