Weird behavior of Vi

Thread Tools Search this Thread
# 1  
Weird behavior of Vi

Hi there,

I am a bit puzzled by a weird behavior of Vi. I very simply would like to add increased numbers in some files. Since I have many thousands entries per file and many files, I would like to macro it in vi.

To do this, I enter the first number ("0001") on the first line and then yank it, insert it at the right place one line below, increment it and return to starting position on the line.
4y<right arrow>
<down arrow>
<left arrow>
[Ctrl + a]
4<left arrow>

And it works Smilie ... by batches of either 7 lines, 70 lines or 700 lines Smilie . Because after each number "7", the auto-increase jumps to the next X0, X00 or X000!? Smilie
Examples :
... 0006 0007 0010 0011 ...
... 0036 0037 0040 0041 ...
... 0076 0077 0100 0101 ...
... 0156 0157 0160 0161 ...
... 0776 0777 1000 1001 ..., etc

It doesn't make any sense and I really very much don't understand.... Does anybody know what's going on ? Smilie


[edit: typo]

Last edited by hypsis; 04-27-2012 at 05:01 PM..
# 2  
Octal numbers count from 0...7, 10
This User Gave Thanks to jim mcnamara For This Post:
# 3  
While we're at it - try the nl command
# 4  
ok, I've checked numbering format. I didn't know decimal weren't the default, nor that 'octal numbers' existed for that matter. Even if I know that vi isn't famed for its user-friendliness, I have to say, I'm impressed.

I checked also the nl command. I cannot use it here - it's a very simplified version of what I intend to do - but I'll keep it in mind.

Many thanks
# 5  
And now for a trip in the wayback machine.... Regarding the user-friendliness of vi, if you put yourself back in the days when it was written, it was actually very user-friendly, just in different terms then what that means today.

Back in the 70's remote terminals connected to UNIX boxes via phone lines at maybe 300 baud. Can you imagine today writing a program where you type a command, have to wait a sec or 2 to the results, repeat!?

The developers of vi (Bill Joy, etc) made each keystroke count, which meant very short, cryptic commands (that you just plain had to memorize) sure did a lot. You had to minimize that wait time and get the most bang for the keystroke. vi is super-powerful but you just have to learn all those cryptic commands to really be effecient. Why just keep pressing 'l' (that's an ell) to go right when you can press w for word and move faster that direction? Or even better f for find followed by the letter you need to move to? Much quicker once you memorized the movement commands and that is just scratching the surface.

Did you ever wonder why Bill Joy made the left, up, down, right keys h, j, k, l? The first version of vi was developed on the Lear-Siegler ADM-3A, the first terminal with addressable cursor capability which allowed positioning of the cursor at an x,y location on the screen. Before that, text scrolled up just like paper on the teletype machines which preceded the crt tube terminals (still called tty's, short for teletype). Guess which keys had the arrows on them since there were no separate arrow keys yet?

Image Photo from

And the Tilda (~) was on the "home" button too, which I assume is where we got the ~ as a shortcut for your home directory.

First the curses library was written in C to support the addressable cursor capability, and right after one of the first real games (and still my favorite), Rogue, was developed to test it they wrote the front end to the ex editor, vi (for visual interface).

Here's a great cheat sheet for vi commands: Vi Cheat Sheet There are others out there too.

Anyway, I hope this historical trip down memory lane makes you appreciate your favorite editor even more when put in the context of the era.


Last edited by gary_w; 05-02-2012 at 11:54 AM.. Reason: fixed typos
This User Gave Thanks to gary_w For This Post:

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Mathematics
Difficulty: Hard
The binary number "101001101" is equivalent to the Decimal number "334"
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Commenting out "expr" creates weird behavior

This really puzzles me. The following code gives me the error 'expr: syntax error' when I try to do multi-line comment using here document <<EOF echo "Sum is: `expr $1 + $2`" EOF Even if I explicitly comment out the line containing the expr using "#", the error message would still exist... (3 Replies)
Discussion started by: royalibrahim
3 Replies

2. UNIX for Advanced & Expert Users

Weird TR behavior. Replacing two instance

Can someone please explain what's wrong with the command i use below? tr -c '\11\12\40-\176' ' '< $TEMP_FILE > $TEMP_FILE2 The invalid character/s is replaced with two spaces, the string2 only have 1 space in it. Please help. Sample output: 333243,333244c333243,333244 < ... (1 Reply)
Discussion started by: Jin_
1 Replies

3. UNIX and Linux Applications

weird yum behavior with provides and install

Why could whatprovides not lookup this info for over 10 minutes, but install could install that package in less than a minute? $ yum whatprovides */lsb_release Loaded plugins: langpacks, presto, refresh-packagekit, versionlock ^Cupdates/group 18% 3.1 kB/s | 360 kB 08:28 ETA ... (0 Replies)
Discussion started by: cokedude
0 Replies

4. UNIX for Dummies Questions & Answers

Weird behavior of backslash, please help!!

Hi I am getting absurd behavior of escape character in echos as followed:oinlcso003{arsadm} #: echo "\as shdd" \as shdd oinlcso003{arsadm} #: echo "Well, isn't that \"special\"?" Well, isn't that "special"? oinlcso003{arsadm} #: echo "Well, isn't that \special\?" Well, isn't that \special\?... (3 Replies)
Discussion started by: nixhead
3 Replies

5. Shell Programming and Scripting

awk print behavior weird

Hi Experts I am facing a weird issue while using print statement in awk. I have a text file with 3 fields shown below: # cat f1 234,abc,1000 235,efg,2000 236,jih,3000 # When I print the third column alone, I dont face any issue as shown below: # awk '{print $3 }' FS=, f1 1000 2000... (5 Replies)
Discussion started by: guruprasadpr
5 Replies

6. UNIX for Dummies Questions & Answers

Weird home key behavior

Hi there, I'm using putty to connect to several servers. On every remote machine, the home key takes me at the beginning of a command line. Exept on one machine where a press on the home key outputs the tilde sign (~). Is there any place where I can override this behavior, I really prefer my... (6 Replies)
Discussion started by: chebarbudo
6 Replies

7. UNIX for Dummies Questions & Answers

Weird Behavior of a Script

ok, there's a script i'm working on written in shell programming. #!/bin/sh this script is written to spit out the contents of certain variables inside of it so the output looks something like this: server01=89 server02=69 server03=89 server04=76 now, when i run this script from the... (4 Replies)
Discussion started by: SkySmart
4 Replies

8. OS X (Apple)

Weird rsync behavior

I use rsync to keep a directory in synchronization betwen a Linux box with the hostname brutal and a Mac running OS X 10.5 (Leopard) with the hostname cooper. When I run the following command on my Linux machine: rsync -avz --delete myuserid@cooper:/Library/WebServer/Documents... (2 Replies)
Discussion started by: scotbuff
2 Replies

9. Shell Programming and Scripting

weird behavior of grep -P

I met a problem in using grep -P. There is a text file, temp.txt, whose content is: dddd abc I ran the command: grep -P "\s*abc" temp.txt The result I expected is: abc But, the actual result is: dddd abc Could anyone tell me what is wrong? Thanks. (2 Replies)
Discussion started by: pankai
2 Replies

10. Solaris

Weird behavior on a Sun Fire V120 running solaris 10.

All, After a power loss I went to power on our sun fire v120 that is running solaris 10 and now it will not boot. I tried power cycling it from the lom and pulling the cord but nothing works. All it does is after a power cycle it will start to boot and then start to spit out a bunch of hex... (2 Replies)
Discussion started by: jsandova
2 Replies

Featured Tech Videos