Vi, Macs, and Shells

I’ve so got to get or make a Vim plug in or some thing for this.

So far I’ve come to a cross roads, I can keep my editor or I can become more Emacs compatible. On Windows I use PuTTY for a ssh client. I don’t know what the terminal emulator is but it sucks. When working on Vectra I effectively have no insert/home keys e.t.c. or Numpad which is bad because I’m accustomed to using the home and end keys in my line editing. This means ether live with only cursor keys and backspace for line editing or relearn the Emacs navigation commands. Control+key is used, b for back one char, f for forward one char. p for previous command (up) and N for Next command (down). e for end of line while a is used for end and home key replacements. Using the meta key (generally alt) turns this up a notch and uses larger units such as forward a word instead of a char. I’m used to using control+u and control+w in line editing – I don’t know if control+w has effect in Emacs but control+u doesn’t.

Needless to say I don’t like Emacs ! I used XEmacs as my editor at first but I fell in love with Vim after I started getting into shell use. You could say learning the shell helped me learn Vim and vice versa. I didn’t like vim at first and I’m only now starting to use gvim off windows (konsole is better then cmd.exe). I’m very used to Vim so I am also used to Vi. My vimrc file makes it easier to use but since Vectra is very light on the software I didn’t install vim. Vi is good enough and ee for when I’m just pissed.

Vim/Vi is very simple to use once you get the hang of it, Emacs is just wrist strain. So now I ask my self the question: What about Vi editing mode? The Bourne and Korn shells support it as does the Z shell AFAIK. However I use tcsh which does not. So if I want to use this editing mode that means use another shell. Vectra only has sh and tcsh. Being FreeBSD the csh is actually tcsh but not like how bash is commonly GNU/Linuxes sh. FreeBSD uses ash as s, a very light Bourne shell clone. I could install any other shell I want really and a ruby shell would be kind of cool if it could fuse an interactive shell, scripting and ruby into one package. The problem is if I get used to vi line editing in a shell I’ll be ruined for any other shell !. I’ve yet to decide but to be honest with the Vi editing mode I think sh is livable. It nets the use of cursor keys and command history.

nvi/Vim is very simple. Vi is a modal editor, if you press escape you are in a command mode, if you press “i” or insert you are in insert mode and it’s like most text editors. You litterly change the entire keyboard into/out of modes. In insert mode your keys always insert chars, most consoles let you use the arrow keys, home/end/delete/backspace like normal. In normal mode which can be reached by pressing escape. Every key stroke is a command or switches to other modes. You can move the cursor with the h,j,k,and l keys. The h and l keys move left and right while the j and k keys move down and up. I’ve heard that Bill Joys console had arrow keys on these so that’s probably why they are used this way. It was a little weird at first but now I’m getting used to it. I’ve generally used the cursors.You can delete a char using the “x” key.

You can delete directionally by prefixing a movement key with d. So dh and dl deletes one char to the left or right. Pressing dj or dk will delete the current line and the line below or above. To kill the whole line use dd. You can repeat commands by appending a number, example: dd3 will delete 3 lines. You can move to the start or end of line by pressing ^ and $ this also works with d. You might notice ^ and $ from some studies in regular expressions – I do from a bit of sed/grep/awk learning. You can move forward and back a word at a time with the w and b keys. Much faster then control+key combo and easier on the wrists IMHO! Pressing i puts you into insert mode to enter text, pressing v puts you in visual mode. Escape will bring you back to normal mode. I never used visual mode very much at first but now I find it useful. In visual mode most normal mode commands for movement work the same. Yet when you move the cursor you always highlight or “select” text. You can copy it or “yank” it with the y command and put or “paste” it with the p command. If you want to cut it use the c command. Usually after a cut I think Vim puts you in insert. Pressing : gives you a little command line.

Here you can enter commands but internal and external, set options and more. To edit a file type e /file/name after pressing : for speed I bound ; to do the same as : in my vimrc. To save it’s :w also know as write ! To quit it’s :q note that you press the ” : ” you don’t type it as part of the command. You can override it by suffixing it with a !. Example: force a quit by doing a :q!

We can run shell commands by prefixing them with a “!” like this :!ls ~/Documents. File name completion works and a UNIX shell is better at it then cmd.exe (vim is very portable). Vim might seem a bit awkward at first but once your used to it it’s very fast and effeienct. TO get help type :help to get context sensitive help try :help topic_or_cmd

Using vi line editing in a shell works the same was using Vi only you start off in insert mode instead of normal mode. I haven’t decided what to do yet.

Ya know whats funny…. I started out to write a short post about my feelings but I end up trying to knock out a Vi/Vim intro before my batteries run out.

All roads lead to Vi !!!