My laugh of the day, 2008-09-08

“To bring a MicroVAX to its knees, try twenty users running vi — or four running EMACS.”

I just couldn’t help but smile, nod, and laugh lol. Vi is a fairly light weight program in todays world, and was designed in a time when just moving your text editors cursor was probably slow as watching paint drying. Emacs on the other hand, tends to be rather hefty in most good implementations, I think it was once a cottage indrusty to make light-weight emacsen.

And to this day in the form of GNU and X Emacs is, one small operating system, but a huge text editor compared to the nimble Vi. I don’t go much in for the Vi Vs. Emacs stuff and vice versa, because I use the Vim which is the only thing better then Vi 😉

urxvt & utf-8

Found an interesting problemo tonight with using vim in rxvt-unicode. Since the German umlauts and the old double-S (ä ö ü ß) are a bit tricky for me to make without a copy/pasting then where needed I usually use the alternative (ue oe ue ss) where possible. Since vim 7 has spell checking, I’ve got spelllang set to handle US and British english plus German in the spell checker. Which really works very nice because my spelling is a bit of a hodge podge for those ‘differences’ in English spelling.

While I was working on the translation last night, I employed both Vims spell checker and a translator program to help me with the grammer. Vims spell checker has the lovely ability of being able to correct things, taking the form I can easily get out of a US QWERTY board and replacing with the proper characters (ä ö ü ß), I knew there was some thing I loved about vim xD

The only thing is, trying to open the file again with vim caused it to display weird, all of the umlauts replaced with strange characters. I checked Vims idea of the files encoding and it was UTF-8, just like my system locale settings should be saying.

Yet, (n)vi, cat, and other utilities were showing them fine. Setting the terminal encoding in vim or launching it with LANG=de_DE.ISO8859-1 got them to display properly but still senseless :. My ~/.zshrc sets LANG to en_US.UTF-8, why nothing seemed to work right i dunno. Forcing urxvt (rxvt-unicode) to run with the C locale set (LC_CTYPE=”en_US.UTF-8″) got it working fine.

I’m not familiar with that end of C++ but I wouldn’t be surprised if it relied on the same setlocale() routine as C apps tend to. The FreeBSD handbook said to set LANG and MM_CHARSET and not LC_* variables for the environment. I’ve fixed it so the system kicks urxvt off with the right locale settings so the problem is fixed.

still a little odd imho lol

After looking at Vim 7.x’s omni completion during a conversation in #vim on irc.freenode.net I got an inkling to try making Vim auto complete the end of HTML tags without pressing ctrl-x + ctrl-o each time.

I’m sorry to say, it only took about 3 minutes:

imap </ </<c-x><c-o>

which tells Vim to enter </, press control+x following by control+o which is the insert mapping vim uses by default to do auto completion.

Yes I’m that bored… Haha

Hmm, I did think of an interesting idea which would a ‘collection monitoring playlist updater’ that would use MD5 checksums (or a faster algorithm due to the size of some of Wiz’s mixes). The idea would be a sort of tags-file / flat-file database that maps MD5 checksums of all known files to current file names. If a file name of a checksumed file has changed, update all playlists with the ‘new’ file name.

An interesting idea, especially since I use a mixture of XMMS and MPlayer these days rather then ol’Amarok.

As it would probably take more then ~15 minutes to md5 1.9GB of music files over a sshfs mount on my laptop, it’ll have to wait for another night but what an interesting idea xD

Update

Well, 10% of download complete in about 2 1/2 hours (two and a half)… Interesting although the download speed is only about 20~28kbyte/sec, it is generating enough network traffic that page loads are very slow, normally I can ping www.google.com and get a response average in the 48-62ms range, and maybe 150ms or so to my primary DNS server set by the ISP.

By contrary, the *US* mirror alone for KateOS pinged at > 400ms and still has a just as bad D/L rate, so since it would mean downloading 3 disks from them as they don’t have a copy of the DVD ISO, there’s no loss by a server from a far off place… But I’ve got to admit, if I had the $6… I would by the bloody disk instead of download it LOL.

As I do with many of my pre-planned operations, I’ve assigned this one a code name: Phoenix. Both because it will be raising an old cannabolized PC out of the ashes; and will probably end up either enflaming my rageometer or proving to be worth the trouble…

Here is part of my ~/phoenix.outline file, I’ve worked out a number of things so far. Software needed on the system once it’s ready op, General goals of the overall plan, changes to Vectra, which PC gets what drive, Suggested file system schemes, estimated the probable cost ($95), since time can only be guessed at I factor that as a level of involvedness it will take to get changes done. I’ve also worked out a strnger concept of what each system will be doing. What follows is the tail end of my outline, pointing out the major placement alternitives. I think points 0 and 2 are best, 0 is annoying but probably the best solution given the terrain, although idea 2 is also a nice idea if I didn’t have a fscking parakeet screaming my head off from morning to just before bed time — No wonder they invented WORK !

Ideas:

| 0/ Remote Workstation {
| | Move either Vectra or Phoenix into my room and set the other up
| | in Vectra's current position (Living Room, my PC desk, lower
| | store point).

| | Set up Phoenix? to make use of xrdp server and access it from
| | Dixie, SAL1600, and also if necessary Josephine.

| | Pro's:
| | | Grants a *decent* working environment from my Desktop
| | | without forcing me to use the Cywgin provided x-server
| | | (also an option here, since it's installed on SAL1600).
| | | And without making me use my laptop for every thing.

| | | Takes best advantage of space, e.g. my Desktop (SAL1600) is
| | | the only place I can actually set up a PC to sit at and
| | | use comfortably, hence why my Laptop (Dixie) has been
| | | such a life saver, because I can sit in bed or at a
| | | regular table -- hole problem could be solved with an
| | | LCD Monitor, which I can't afford... Only have 2 CRT's
| | | in the 19 and 17 or 19 inch range.

| | | Further integrates remote access across the LAN, which
| | | is currently limited to all BSD boxes running OpenSSHs
| | | ssh daemon and all systems having SSH Clients installed.
| | | My Desktop having WinXP MCE's built in RDP capabilities
| | | and all other systems RDP Clients.
| | Con's:
| | | Lack of (me) testing RDP based operations for indented
| | | purposes, also no configuration experience with xrdp.

| | | The 'annoyance' of having to use my Desktop as a client
| | | to access another box for getting work done.

| | | Wireless adaptor must be supported by either Linux or
| | | OpenBSD, which could be a bit *hard* to confirm based on
| | | the local shops generic stockpiles.

| | | Due to the amount of local network traffic, it might be
| | | bet to setup the File Server with the Wireless instead
| | | of the Linux system.
| }

| 1/ Bedroom Work Platform {

| | Set up Phoenix? in my room with Wireless adapter,
| | possibly attempt to cannibalize Vectras CD-ROM drive so
| | that Vectra becomes reliant on Floppy disks only. Wish I
| | had a way to either give all systems a card reader or a
| | floppy drive... Would make life easier!

| | Pro's:
| | | Less disturbing of existing systems then other
| | | ideas.

| | | Gets me further away for
| | | disturbances/distractions

| | | Can use Monitor, Keyboard, and Mouse, as well as
| | | rest of PC physically rather then remotely

| | Con's:
| | | No decent working environment in my room to use
| | | a full size PC without purchasing either an LCD
| | | Monitor or setting up a /or another PC Desk in
| | | my room; I only have the one that SAL1600 and
| | | Vectra are hooked up to.

| | | I can hear my family from at least 10 metres
| | | out side of the building! Let along every where
| | | inside of it.

| | | My laptop might get a lot less use, since most
| | | times I use my laptop it is in my bedroom.

| | | Any possible working environment I could arrange
| | | in my room is likely to be much less then
| | | comfortable for physically sitting at a PC
| | | without buying another PC Desk.

| | | Requires Wifi to be compatible with Linux.
| }

| 2/ Bedroom Game box {

| | Move SAL1600 into my room and swap the Ethernet NIC with
| | the Wireless Adapter.

| | Place Phoenix? in SAL1600's place in the living room

| | Pro's:

| | | Eases shopping for wireless adapter

| | | Moves my Gaming system away from most common
| | | 'interruptions'

| | | Better chance of hearing people on TeamSpeak !

| | | Limits potential for using my laptop less

| | Con's:

| | | No decent working environment in my room to use
| | | a full size PC without purchasing either an LCD
| | | Monitor or setting up a /or another PC Desk in
| | | my room; I only have the one that SAL1600 and
| | | Vectra are hooked up to.

| | | Any possible working environment I could arrange
| | | in my room is likely to be much less then
| | | comfortable for physically sitting at a PC
| | | without buying another PC Desk.

| | | With a work platform placed in the living room
| | | (in SAL1600's place), it would be even *HARDER*
| | | to get freaking work done.

| | | Being in my room on the game box would likely
| | | make it harder for Ma to call me when she needs
| | | things done.
| }

The braces denote folds and the pipes I inserted into the copy/paste so it displays as I see it in my text editor. I’ve configured vim to run a function when ever reading or writing a file with a .outline extension, the function sets settings that I find help write an outline and try to categorize my thoughts more clearly. This is actually how my vimrc file sets different style and other minor options to suit the language I am currently editing, for example a standard tab (visually equal to 8 spaces) when working with C files, and 2 actual spaces for Ruby, e.t.c.

The Pipes or ‘|’ are not really in the file, they just show the tab-deliminated indentation. While I don’t use this when editing source code, I find it works nice for things like this. Normally foldmethod is set to indent, and changed to ‘syntax’ where supported suitably. For outlining, since I didn’t have time to work on a more suitable method of folding, I mearly set it use single braces and fdm=marker; usually it uses 3 braces but I rarely use the marker foldmethod.

Heres my function in vimrc:

function! My_OutlineMode()
setl tabstop=8 shiftwidth=8 noexpandtab
setl listchars =tab:| " Mark t's with |'s
setl list
setl spell
setl autoindent smartindent
setl showmatch matchtime=3
setl matchpairs+=(:),{:},[:],<:>
" Fold by tabs
"setl foldmethod=expr
"setl foldexpr=getline(v:lnum)[0]=="\t"
" Fold by braces
setl foldmethod=marker
setl foldmarker={,}
endfunction
autocmd BufNewFile,BufRead *.outline call My_OutlineMode()

Although it is probably unnecessary on most vim builds but the autocmd should probably be wrapped in an

if has(“autocmd”)
autocmd goes here
endif

hmm, supper time

Is t his abuse?

I hit http://www.vim.org/ to look for some script and stopped by their tips section. Since I didn’t have any thing else, well I started reading in the tips section. I know its a nice spot to find un-common keybinds and some nice macros and functions.

Is this abuse of the ‘tabbed browsing’ features ???

Free Image Hosting at www.ImageShack.us

Hehehehe I think so!!

$MYVIMRC

My current ~/.vimrc file. The {{{ & }}} mark the locations of folds, I elected to ues folding marks for my rc file. And when I have time to read how, I probably will set it to allow sectional jumping.

In short form, the file ensures that Vim does not read my .exrc file, does not try to be strictly vi compatible. Auto reads changes to files, keeps files at 80 char width (see tw), make for a more comfortable movement pattern near EOL. Yank into the clipboard, enable syntax folding on new files (my preference for sources), DOS EOL for new .txt files. Set somes sizes, enable my ‘HUD’ ^_^, turn on a nice colour scheme, and syntax highlighting. Set fonts, and a few useful keymaps. :help <option> generally works for looking things up in the manual (help can be shortened to he. with no sexist intent.)

"Terry M. P***** personal vimrc file

" vim: set ts=6 sw=6 expandtab foldmethod=marker foldcolumn=1 foldlevelstart=99:
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" WARNING !!!
" This file must have UNIX end of lines to avoid errors when starting
" under unix. Use the pdos2unix and punix2dos sh scripts to convert or
"
" perl -p -e 's/n/rn/' inputfile > outputfile # UNIX to DOS
" perl -p -e 's/rn/n/' inputfile > outputfile # DOS to UNIX
"
" on the command line
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Abstract
"
" Editing Preferences - set options related to editing tasks
" User Interface Preferences - set options related to appearance
" Keybinds & Commands - mappings / created


"""""""""""""""""""""""""""""""
"Editing Options {{{
"""""""""""""""""""""""""""""""

"Don't be VI compatible - Keep this at top of file !
set nocompatible
set noexrc

"automatic re-reading of changed open files
set autoread


"ingore case when searching
set ignorecase

" Use the system clipboard as the default register
set clipboard=unnamed

"Buffer related {{{
"Allow backspacing over everything in insert mode
set backspace=indent,eol,start
"Allow to go one space past EOL
set virtualedit=onemore
"Allow left/right movement at EOL to move to start of next line
set whichwrap=hl<>
"Wrap text at n chars with a line break
set textwidth=80
"set wrap
set linebreak

"Folding
if has("gui_running")
set foldmethod=manual
set foldcolumn=0
else
"Use sytanx folding in console mode
autocmd BufNewFile,BufRead *set foldmethod=syntax foldcolumn=1
endif

"}}}

"Size stuff {{{
"Tab length and shift lengths
set tabstop=8
set shiftwidth=4

"Set min # of spaces for numberwidth. It grows as needed
set numberwidth=2

"Set tab menu 0=never, 1=when more then one, 2=always
set showtabline=1

" Start with folds open
set foldlevelstart=99

"}}}

"File related {{{

"Set prefered line file formats
set ffs=unix,dos,mac
"Enable filetype detection
filetype on
"Turn off ft plugin and indent
filetype plugin off
filetype indent off

" Create new.txt files notepad ready
autocmd BufNewFile *.txt set ff=dos

"Enable syntax highlighting
if &t_Co > 2 || has("gui_running")
syntax on
endif

" Highlight strings inside C comments
"let c_comment_strings=1


"}}}

" }}}
"""""""""""""""""""""""""""""""
" Keybindings {{{
"""""""""""""""""""""""""""""""

"Maps {{{

"Use the ";" as a duplicate of ":" makes life so much easier
"for some odd reason it cannot be followed with a comment on it's line!
:nma ; :

"F1 turns on spellchecking in current buffer
map :setlocal spell spelllang=en_us

"F2 turn on line numbering
map :set number

"F3 turn on self indenting magic
map :set smartindent autoindent

"F10 rids us of ^M after carriage returns
map :%s// /g

"}}}

"}}}
"""""""""""""""""""""""""""""""
"User Interface Options {{{
"""""""""""""""""""""""""""""""

"Always show the status bar with file name e.t.c.
set laststatus=2
"Show %of file in statusbar
set ruler

"Command line completion lists possible matches
set wildmode=list:full

"Start with mouse support
set mouse=a
"Hide the mouse when typing text
set mousehide

" Dependant on GUI on/off {{{
if has ("gui_running")
"Set colo and options
colorscheme denim
" Set 'go' to:
"autoselect, console dialogs, tabpages, icon, menubar, show grey menu
"items, tearoff menu items, Toolbar, always right scrollbar.
set guioptions=aceimgtTr

"Make pointer an I-Beam in insert mode
set mouseshape=i:beam
"for spellchecking
set mousemodel=popup_setpos
"set cmd line size
set cmdheight=2

"Set windows specifics
if has("win32")
"Windows font
set guifont=Fixedsys:h7:cANSI
"Set x11 specifics
elseif has("x11")
set guifont=Fixed Semi-Condensed 13
set columns=80
set lines=35
endif
else
"set colors for terminal
colo advantage
"set cmd line size
set cmdheight=1
endif

"}}}

" }}}

NTS

Have a T-Shirt made that shouts:

I don’t care about spelling unless it involves Vi !

Vi User How-To

Welcome to an introduction and usage study of one of the worlds most common text editors. It is also my favorite style of editor. We cover several sections each detailing a given aspect of the Vi editor.

Table of Contents

Short history
Which Vi is my Vi ?
Initial Fear
Learning Vi
Required Commands
Helpful Functions
A few extra commands
Making sense of Vi options
Deletion Wars
Cut, Copy, and Paste the Vi style !
Options and configuration
How to make a exrc file

Document Version: 0.90.0

This post has the underlying assumption that you want to learn to use the Vi text editor but know jack about it. I won’t insult you but I’ll try to teach it without being to terse or “hand holding”. We all need help but one has to put in a little bit of effort to master a program.

I have always cared more for content and understandable English then for closely following the “laws of the English anguage” so forgive any grammatical errors and ether curse or help improve the content 😛

Short History
In 1976 a man named Bill Joy wrote the Vi text editor for an early BSD release. It took the existing ed and ex line editors and created a visual interface. While ex was a simple line editor vi gave us an interface much more like what we are accustomed to in this era.

Vi is a modal text editor which means that depending on what editing mode one is in at any given time what each key does changes. Vi has thankfully only two editing modes of importance command and insert. Unlike common editors such as Emacs or Kate commands are entered by shifting the entire keyboard into command mode and back into insert mode to continue inserting text. This modal concept is probably the biggest adjustment new users have to make when learning Vi. Some notable influences on the Vi command set was the ADM3A terminal which had the Esc and left Control keys where the Tab and Capslock keys are on modern US_QWERTY keyboards. There was also arrows on the H, J, K, and L keys which intern became the Vi movement keys.

Picture of ADM3A Keyboard

Which Vi is my Vi ?
There have been many vi implementations and clones through the years and on many systems but you can always count on an Unix to have a Vi. By high decree of the POSIX (Portable Operating System Interface for uniX). It would be best that before you try to start learning how to use Vi you learn what type of Vi editor you have. Many GNU/Linux systems will use a Vi clone in place of Vi while BSD Unix’s use nvi. This how to should be relivent to every Vi/Vi Clone but most Vi Clones have a lot more to offer then Vi does.

Vi is the classic BSD
implementation now free and open source under a BSD style license.

Nvi is a re-implementation of Vi used for the 4BSD release when the original Vi was considered encumbered code. This is what is like wise used on Free, Net, Open, PC, and Desktop BSD and the focus of this how to.

Elvis is a Vi clone that adds a number of features and commands. Elvis functions on Unix, Dos, NT, and OS/2 systems both as a console and graphical application. It is standard issue on Slackware Linux for the systems vi program.

Vim or Vi IMproved is a Vi clone that implements many additional features and options. It’s known to run on many platforms including Amiga, GNU/Linux, Mac OS X, Windows, OpenVMS, OS/2, and Unix like systems. Vim supports several graphical user interfaces including Motif, GTK1, GTK2, and Athena versions. It is also what this post was written with.

Vile was initially derived from an early version of Microemacs in an attempt to bring the “modern” benefits of the Emacs multi-window/multi-buffer editing paradigm to users more comfortable with the vi command-set. Vile functions on DOS, Windows, OS/2, GNU/Linux, Mac OS X, and Unix like systems.

Viper-mode of the popular Emacs editor tries to emulate many common vi commands and may prove interesting to emacs users and humorous.

It does not matter what Editor one uses as long as one is happy, productive, and effective but I would recommend using a Vi Clone with good documentation. So know any good jokes about Vims 25,000,000,000 page manual ? Hehehe.

You may invoke the vi editor from a console window by typing “vi”, if your using another type of editor or “vi clone” please consult it’s documentation.

Initial Fear
The traditional vi runs in a command window which is enough to scare off many new users. While newer Vi Clones such as Vim and Elvis have graphical user interfaces that can run with such luxurious features as tool bars and menus it is important to know that the editors are still available in the command line environments without loss of functionality.

One of the most confusing things to scare you about learning Vi is the concept of editing modes. Most users are used to an editor that starts with and is always in “insert-mode” that is you type on the keyboard it and writes text to the screen. Vi by default starts in a command mode where the keys are used to issue editing commands such as delete, replace, yank (copy), paste, cut and movement keys and such. When one wants to start writing text they have to enter insert mode. Once you get sed to this idea you will start to grasp Vi much better. When you are working in insert mode Vi will behave in a similar manor to what most users expect a few differences aside (like the Esc key and copy/paste commands). To indirectly quote a man named Jon Lasser about vi editing modes.

When you move your (mouse) pointer out of the screen area, you can’t type in text. You have, in effect, moved from insert mode to command mode. “It’s the same thing,”

Most implementations of Vi including nvi should be able to make use of ones cursor (arrow) keys and the insert/home/pgup/del/home/pgdwn clusters we take for granted but using the arrow keys are less effective then using command mode & the classic movement keys. I’d say you should try to use the cursor keys for simple movement at first because they work in any mode and are less foreign. When some day you find yourself without working cursor keys you will be bloody
happy you learned to use H,J,K,L instead of LEFT, UP, DOWN, RIGHT. Trust me it can happen, I once had a very bad system boot the kind your usually lucky to be able to fix without a rescue disk kind. I had to edit a file and my choices of editors were rather limited (ed, ex, vi, ee). When I ran vi it could not use my cursor keys forcing me to use the H,J,K,L cluster in it’s place. Never before was I so glad to know two ways of doing the same thing in a text editor !

Learning Vi

I will split this section into several groups of commands. When I first tried to learn Vi(m) I didn’t like it because I could not figure it out at the time. After a while on the FreeBSD command line I learned how to use it. In the process I also learned the easiest way to learn how to use Vi, aside from using Vim instead (:help) was to learn things in small pieces. It won’t do you any good to try and learn Vi all at once but if your able to just sit down and inhale it I’ll probably edit in a cheat sheet or a link to one at the end of this how-to.

Required Commands

So named because these are what I feel are the fewest commands one needs to know in order to use Vi. Maybe not use it well but use it as well as Notepad is a good editor. While we are on the subject of Notepad. Just to say it, notepad is a good editor for several reasons:

It is on nearly any Windows system, it’s very simple and light weight.

You don’t need a Ph.D to use it.

It’s also very week and very basic.

Vi like many Vi users prefer Speed, Power, and Efficiency over a small inertial learning curve. Many people say Vi is not intuitive to learn but I must disagree it is only a matter of adopting ones mind to shifting between insert and command modes. The more one learns with Vi the more productive they will be but no one need learn every thing on day one !

These are the core super simple commands you have to know to use Vi like most editors.

Key         Action

h Move left one character - the left arrow does this as well
j Move down one line - the down arrow does the same thing
k Move up one line - the up arrow does this too!
l Move right one character - Right arrow yet again.
Esc Enter Command Mode /or cancel commands
i Enter insert mode - the Insert key will also work
x Delete the character under the cursor - just like the Delete key.
ZZ Save file and quit Vi

To tell the truth compared to using Notepad you only learned 3 commands. Esc, i, and ZZ or enter command mode, enter insert mode, and write file and get me out of this crazy editor!

The h, j, k, l, and x keys are analogous to the arrow keys and the insert and delete keys on your keyboard. The only difference is these keys work when nothing else does. Some terminals don’t support luxuries well such as home and end keys so when working on a machine from a remote session or laptop these can be your best friends. You should be able to live with having to press ESC to use commands and go to insert mode to input text.

Helpful Commands

These are more keys and commands that are not necessary to edit a file but do make live a lot easier especially if you often find your self editing text not just creating it. If you have some experience with some thing called regular expressions a few of these might even seem familiar to you.

Key         Action

: Enter "ex" like commands in a "command line" mode
:w Write changes to file
:q Quit Vi
:e file Open file for editing

/word Find "word" much like Control+F in many other editors
n Go to next occurrence of the search term below the current
N Go to next occurance of the search term above the current one

a Enter insert mode right of the cursor
A Enter insert mode at the end of line
o Insert line below cursor
O Insert line above cursor
w Move forward one word
b Retreat one word
$ Move cursor to the end of the line
^ Move the cursor to the start of the line
Control+u Page up half a screen
Control+d Page down half a screen

u Undo previous command(s) - some Vi clones have unlimited undo/redo
Control+r Redo the undone command(s) - same as above ^

r Replace one char and return to command mode
R Enter Replace mode - works like pressing insert in most editors
c Change, takes an operator like d. example: cw=changes a word
d Delete using a following movement command (see below)
dd Delete entire line

None of these commands are necessary to know but they sorta make life easier. Personally I find these much easier on the wrists then Emacs which uses key combinations using the Control and Meta keys instead of a command mode.

A few words about the “:” key, it enters a little command line mode. When you press the : key in command mode it gives you a command line to type an ex (extended editor) type of command. After you have typed the command you press enter to run it and should return to normal mode. If you need to force a write or quit you can append the “!” Symbol to it. If you are a ex guru or need to enter many commands in this way you might try the “Q” command to enter Ex mode. For example the ZZ command is the same as :wg. One can mix and match actions and movements very well in Vi, for example if one wanted to delete to the end of the line you could use command mode to enter d$ and delete from the cursor to the end of the line. When one shifts between command and insert modes often in there editing style you soon find the a, A, r, o, and O keys very useful. I’ve mentioned a few other modes then command and insert but they are of little importance to you unless your into reading good ocumentation. Consult your Vi implementation for details, for users of nvi it’s nothing to fart about at this stage of learning. Many commands allow one to specify a location or a movement. This is especially true for using the commands for deletion, joining text, copy/cut/paste, and multiple editing buffers (windows) if your vi supports it.

You might want to get used to using most of these commands or at least the concepts be fore we try to tackle such tasks as more advanced delete or copy/paste commands. A coffee break about now is a very good idea.

A few extra commands

These are other commands useful to users but I broke them off from the above list to ease session based learning.

Key         Action

:!cmd Execute shell command cmd.
:command! Force command to run, such as force write-quit (:wq!)
:r!cmd Run cmd in shell and insert it's output in the file

G Go to end of buffer (the bottom of the file)
1G Go to line one in the file
nG Go to line n. So 10G means go to line 10

>> Shiftwidth text over one indentation level to the right
<< Shiftwidth text over one indentation level to the left

One cane execute commands from vi that one would usually run in a shell such as bash or cmd.exe. :!dir b “C:Program Files” would be executed just as if one ran the dir command from cmd.exe or command.com. If you want to nab the output of a command into your file use :r!command this is very good if one needs to quickly grab some data thats a fast pipe away. The G command is a go to without any arguments it goes to the bottom of the file. If one was to type a number before it it would go to that line number. The >> and << are useful for shifting text around but have likely little need for users not into programming or scripting e.t.c. So I have nothing to say about these commands. Making sense of Vi optionsOne of the worst things is that by default vi generally does not tell you what mode you are in or where the cursor is this can make life harder. Lucky for us Vi has the ability to set options. Really this belongs in a customizing vi section and I’ll probably paste it there but I think knowing some of this now will help you. You can set options thus turning them on, off, or setting a value :set option :set nooption :set option=10 If you want to see all the options available you can type :set all if you have a good Vi clone you should be able to get some documentation on what all of these do, for the sake of making Vi more friendly we will cover some good stuff here. :set showmode :set ruler ;set ignorecase These three options (in order of appearance) will make vi show you the current mode at the bottom of the screen, show you the cursors position as line,character at the bottom of the screen, and turn off case sensitivity when searching in a file. You can make a startup file that vi will read when it starts that will set options for you. Ex/Vi and Nex/Nvi use the /etc/exrc and ~/.exrc files but depending on your implementation it may be different such as Vim or Elvis. I don’t have much experience with Elvis but for Vim it reads the .vimrc file(s). You can turn these off pretty easy like so :set noshowmode :set noruler :set noignorecase If you want to make a .exrc file for your self you can store commands in it that are what you would type after hitting : so a .exrc file enabling showmode would look like this: set showmode and saved as ~/.exrc if you want to leave a comment in the file preside it with a single ” quote. The ” Comment marks that entire line after the ” character not to be read when starting up. A few options that may interest you are autoindent, tabstop, shiftwidth, wrapmargin, and warplen. By default when one tries to type past the end of the screen it rolls to the line below on screen but is treated as one long line. One can try and make this more like most editors word wrapping with some play time. I will only discuss the autoindent option since it is some thing you will ether long for or hate if you use vi for editing code, scripts, web sites e.t.c. When one sets autoindent on vi starts a new line with the same indentation as the last. The word indentation is a little odd in my opinion if your not a programmer so I’ll give a short example of how it goes.

if i is-greater-then 0
do this code
and this code
else
do this instead
endif

If typing that with autoindent on pressing return after typing “do this code” would automatically indent the next line to the same level. You can press Control+D to kill the autoindent such as if you wanted to place the “else” in our pseudo code at the same level as the “if” and “endif”. Deletion WarsIf you remember awhile ago when we both were still sane. I mumbled about being able to combine a command and a movement. This is pretty much true with most movement, deletion, and “visual” commands (visual as in cut, copy, paste). x deletes the letter under the cursor but what if we want to delete some thing else? We can use the d key along with a movement specifier if you recall the movement keys h, j, k, l, $, ^ we can combine them all with d to make it mean delete this way. So d^ really means delete to-start-of-line. This makes for very versatile work and it’s not just limited to deletion. Much like we can use a number and G to go to a line like 275G to go to the 275th line of a file. Nvi users will especially need to know this for dealing with copy/paste as it lacks a Visual mode that makes it more like other editors. A very fast way to delete an entire line is the dd command or deadly delete 🙂 You can prefix a number of lines to a command as well, so for example 10dd will delete the current line and the next ten for you. Unlike most editors Vi does not really know you have a mouse, although Vi Clones should if they have a GUI. Some like Elvis and Vim have a “visual” mode that can highlight text using movement keys and then delete it or do the cut, copy, and paste antics with it.

Key         Action

y Yank (copy) - selects text in a similar manner to the d command
yy Yank line - selects text in a similar manner to the dd command
yyp Duplicate line - copy/paste current line on the line below.
p Put (paste) text
v Enter visual mode - for some Vi Clones

One should really know both ways if possible. Personally I prefer visual mode, it’s more like what we are all used to. That is you select (aka highlight) text then do with it what you want, such as copy or delete. With classic Vi as included in FreeBSD at least one will get an error. If one wanted to copy the current line and the next tree. You would type 3y in command mode. Go to where you want to paste it and press p key in command mode. This is more or less how it works in traditional Vi. This is how it can also be done in a Vi clone like Vim. You can enter visual mode (v key). Once you do that the editor starts treating the cursor movements just like when you old the left mouse button and start dragging the pointer around. Only it works without a mouse ! Once you’ve high lighted some text you can act on it.So for example if you pressed “vwwd” you would have just deleted from the current cursor position to the next two words. You can use the “c” command to “cut” in visual mode. I have not tried elvis much but it should be similar to vim. Search and Replace If you are familiar with regular expressions, sed, awk, ed, or ex you should be at home right here. The search & replace takes syntax like this ‘n,m s/find expression/change expression/cmd’. So if I wanted to change every occurrence of ‘vi’ to ’emacs’ in this file I could do this. :1,$s/vi/emacs rules/g That is from line 1 to end of lines search for the string vi and replace it with emacs globally. If I only wanted to change it for n through m lines I could have tried some thing like this :260,285s/emacs/vi/g Regular expressions are similar to the wild cards used by the shell but they are different. Same concept (imho) but different syntax. Much like C and C++ maybe. A detailed Analise of regular expressions would be out side the scope of this how-to and totally irregular 🙂 I suggest the following links for more info about regex (regular expressions) http://en.wikipedia.org/wiki/Regex http://www.regular-expressions.info/ Back in the days before operating systems when software ran on the bare hardware. Stuff like this “regular expression” mumbo-jumbo was a thing just for the uber-nerdy scientist but now it’s in the power of your editor. It should also be worth learning how to use regex. As it is a common syntax with many uses. The better you know regular expressions the better you will be able to use tools like sed, grep, awk, find, perl, ex, and many more. Options and Configuration We touched on this back in section 4.4.Making Sense of Vi options but will go over a few things again. Saves your scroll bars eh? 🙂 Vi has a number of options that adjust the way it behaves, here is screen dump of the default setup of nvi. As used on FreeBSD 6.1-Release.

~
+=+=+=+=+=+=+=+
noaltwerase noextended matchtime=7 report=5 term="xterm"
noautoindent filec="" mesg noruler noterse
autoprint flash nomodeline scroll=12 notildeop
noautowrite nogtagsmode noprint="" nosearchincr timeout
backup="" hardtabs=0 nonumber nosecure nottywerase
nobeautify noiclower nooctal shiftwidth=8 noverbose
cdpath=":" noignorecase open noshowmatch warn
cedit="" keytime=6 optimize noshowmode window=24
columns=85 noleftright path="" sidescroll=16 nowindowname
nocomment lines=25 print="" noslowopen wraplen=0
noedcompatible nolisp prompt nosourceany wrapmargin=0
escapetime=6 nolist noreadonly tabstop=8 wrapscan
noerrorbells lock noredraw taglength=0 nowriteany
noexrc magic remap tags="tags"
directory="/tmp/"
msgcat="/usr/share/vi/catalog/"
paragraphs="IPLPPPQPP LIpplpipbp"
recdir="/var/tmp/vi.recover"
sections="NHSHH HUnhsh"
shell="/usr/local/bin/ksh93"
shellmeta="~{[*?$`'""
Press any key to continue [: to enter more ex commands]:

You can get a screen like this by using the :set all command. Every option or “variable” can be turned off by appending ‘no’ to the command. So if we wanted to turn on autoindent we would :set autoindent We could also have used the short form and typed :set ai but that makes it harder to read. Why this matters I’ll tell you in a sec 😛 To turn it off we would then type this. :set noautoindent Some options take a numeric value and are set like this :set shiftwidth=4 I’ll try to quickly document each of these options the best I can ones of value. So you can choose what you prefer. I’d suggest if you want to modify Vi’s behavior to test a few options to see how you like the changes. If I have no information about the option, it is not listed. Option: autoindent Short form: ai Value: on/off Default: noautoindent Description: When turned on ‘ai’ will automatically start the new line to at the same depth as the previous line when breaking lines (i.e. pressing enter). The value of the ‘shiftwidth’ variable is used when inserting tabs. When your done you can undo the autoindent by pressed the control+d. I’ve yet to figure out if it is a bug or a configuration error but if tabstop and shiftwidth have different values. Control+d will not un-indent the line correctly if sw and ts are not equal. Line one line two Autoindented Cntrl+D Option: autoprint Short Form: ap Value: on/off Default: noautoprint Description: I don’t see any effects but my reference says ‘Display changes after each command.’ Option: autowrite Short Form: aw Value: on/off Default: off Description: Automatically write changes to file after certain events. Option beautify Short Form: bf Value: on/off Default: off Description: Ignore all control characters during input (except tab, newline, formfeed). Pressing control+letter in insert mode when no command exists will result in text like this by default. How to delete a tpyo�� No I’m not trying to insult emacs users, I would probably use M-B M-D to fix such a typo when using Evil Macs. Option: columns Shot Form: col Value: numeric Default: varies Description: The number of columns to use for the text area. Example, how to set vi to 85 columns wide. :set columns=85 Option: edcompatible Short Form: ed Value: on/off Default: off Description: Use ed-like features on substitute, probably more useful for Bill Joy then you or me. Option: errorbells Short Form: eb Value: on/off Default: on Description: Sound the system bell when you make a booboo. Option: exrc Short Form: ex Value: on/of Default: off Description: Vi can read an exrc file that will run a set of commands at startup. Basically a configuration file for setting your options (see next chapter). Option: hardtabs= Short Form: ht= Value: numeric Default: 8 Description: Set boundary for hardware tabs, may be useful for a Teletype. Option: ignorecase Short Form: ic Value: on/off Default: off Description: Ignore case in regex expressions. Option: lisp Short Form: ? Value: on/off Default: off Description: Turn on lisp mode, I think it aids the formating of old lisp code. Option: list Short Form: ? Value: on/off Default: off Description: Display all tabs, end of lines. Turn this on for fun 🙂 Option: magic Short Form: ? Value: on/off Default: on Description: Enable more regex expressions Option: mesg Short Form: ? Value: on/off Default: on Description: Allows mesgs to be sent to terminal, see man mesg(1) Option: number Short Form: nu Value: on/off Default: off Description: Enables line numbering, this can help when debugging files. I usually have a mapping to enable it with the F2 key in my ~/.exrc file. Option: prompt Short Form: ? Value: on/off Default: on Description: Enalbes the ‘:’ prompt, if you disable this you can make ex behave more like ed. You probably don’t want this. Option: readonly Short Form: ro Value: on/off Default: off Description: Prevents you from writing the file unless you override it like so. :w! Option: redraw Short Form: ? Value: on/off Default: off Description: Redraw screen when edits are made, probably works like the Control+L command (refreshes screen). Option: report= Short Form: ? Value: numeric Default: =5 Description: Report changes if they effect more lines then report=n. Such as when using the delete/yank/join commands e.t.c. Option: shiftwidth= Short Form: sw= Value: numeric Default: 8 Description: How many characters to use when shifting width with the >> and << commands e.t.c. If you plan to use autoindent, the value of sw and ts should be the same (see below). Option: showmatch Short Form: sm Value: on/off Default: off Description: The cursor will flash and move to the openning {, }, (, ), [, or ] when typing a closing one on screen. Option: showmode Short Form: ? Value: on/off Default: off Description: Shows which mode you are in such as command, insert, append, or replace. This is so useful its a perfect choice for the beginners exrc file. Option: tabstop= Short Form: ts= Value: numeric Default: 8 Description: How many characters to display a 'tab' as, mostly of use for programmers. Common choices are 2, 4, 6, 8, 10, 12. It has been suggested that one should not change this setting but instead adjust the shiftwidth setting. I can only say from personal experience if you change tabstop but forget to change shiftwidth to the same. Auto-indent will be a bit off :-) Option: wrapmargin= Short Form: wm= Value: numeric Default: 0 Description: Set the right margin. Setting a value greater than 0 will word wrap n spaces from the edge of the screen. So :set wm=5 would make the display wrap lines when ever it hit the 5th to last line of the terminal. Option: wrapscan Short Form: ws Value: on/off Default: on Description: Searches wrap around end of file How to make a exrc fileThe exrc file is very simple. Commands are read from the ~/.exrc file just as they are from the ‘:’ command line in Vi. Placing this line in your exrc file set autoindent Is the same as tying :set autoindent in command mode. You can use the double qoute or ” character to comment a line. ” This line is not read by Vi set tabstop=6 Here is an example of what my ~/.exrc file might look like with extra comments.

" Tell me what mode I'm in between coffee breaks
set showmode
" Press F2 to turn on line numbering, make the ^M with ctrl+v ctrl+m
map :set number
" Alias ';' to :
map ; :

UNDER CONSTRUCTION

__            ___      ___  
| | / / / /
| || / / / /__/ /
| || / / / __/
| || / / / ___
| || / / / / /
| || / / / / / /
| || / / / / / /
| || / / / / / /
| || / / / / / /
| ||/ / / / / /
| |/ / / / / /
| / / / / /
| / / / / /
| / / / / /
|__/ / /__/ /
__/ __/

vimrc

Post best viewed from here

Ahh what a day. I’ve spent most of my time ether on the forums or in my beloved editor of choice (vim). I desided for some odd reason to rewrite my vim resource files. I’ve more or less completed my ~/.vimrc file and will worry about my ~/.gimvrc file later. Really I rarly use the GUI off win32. I basically like using vim in konsole because I can quickly step in and out of editing, ether by forcing vim into the background (control+z, type fg to return to it). Yet because cmd.exe is the worst terminal I have ever used, poor if any support for cut, copy, and paste. Ignores the mouse for the most part and Windows has the tab completion of a fart in the wind. I’m kinda getting used to zsh’s after using tcsh so much hehe.

Heres my vimrc file so far, edited for a few things. The syntax is about as simple as a shell script or “vim script” but the ” double quote works like the # and // comments in most languages. White space it doesn’t care for but it does care about line endings. Since I share most things between Windows XP, PC/Free BSD, and GNU/Linux + several computers I have to be portable in many ways. I started the file on Windows with my file format set for Win/DOS end of lines (:set ffs=dos), vim detects it and uses whats there. I usually set mine as “ffs=dos,unix,mac” so I don’t have to convert my files End of Lines (EoL) when I send some one a text file. If I use UNIX eols theres no carriage returns in Notepad, it’s too dumb to figure it out unlike many many other editors. Sad through is you can always count on some one to have notepad or a simular editor. Gnomes editor and KDE’s KWrite are actually rather nice though. When I tried to run my now complete vimrc on PC-BSD I got a zillion errors and I new I didn’t screw it up that bad, infact only one entry was wrong. I quickly figured out it must have been the line feeds, the fact that I had just setup a keybind to strip off the pesky ^M’s you get in some files helped hehe. I couldn’t find any quick ways to convert the EOLs so I looked them up in Wikipeda and found a way to do it with pearl, I now have a pdos2unix and punix2dos script to do the job when given an input file name and an output file name.

I’ve been told customizing Vim can be bad b/c of having to work with standard vim/vi but I’m a fruit -> If I want Vim I call vim and if I want Vi I call vi. FreeBSD uses nvi for vi, not vim like some GNU/Linuxes do. If some Linux Distro doesn’t make vim start as vi compatible without special changes it’s not my problem. I learned to use vim with just the example vimrc file. After that using Vi was easy after an hour or two. I also remember which I’m using by the fact that I call vi as vi and vim as vim + the status line I keep around.

Lines that start with two “‘s are comments just for this post

"Terry M. P***** personal vimrc file

"""""""""""""""""""""""""""""""
"Editing Options
"""""""""""""""""""""""""""""""

"Don't be VI compatible - Keep this at top of file !
set nocompatible
""Setting vim to be vi compatible makes changes to make it more pure Vi, I don't care for
""this as this is VIM not VI, if I wanted a pure Vi clone I'd use one.

" allow backspacing over everything in insert mode
set backspace=indent,eol,start
""This makes life a lot easier, just trust me.

" Wrap text at n chars with a line break
set textwidth=80
set wrap
set lbr
"" To keep console portability I used to break my lines around 76~78 char
"" I'm trying this to make Vim more like other editors. Out of the box when you write
"" a line two long for the screen it continues on the line below and is numbered as one
"" line. With these settings it breaks them like most other editors at my specified
"" 80 chars. Not sure if I will keep it but worth a test. -> Prolly good for Vim newbies

" Use spaces instead of tabs
set expandtab
set tabstop=6
""I generally like spaces and monospace fonts more for indentation and coding.
""I do like using tabs for manually aligning data in a table in ASCII.

"set min # of spaces for numberwidth. It grows as needed
set numberwidth=2
""This keeps down the size used for the thing /w the line numbers. Defualt is 4.

""""""""""""""""""""""""""""""
"Tabbed Editing
"""""""""""""""""""""""""""""""
set showtabline=1
""Only show the list of tabs when theres more then one. 2=always, 0=never

"set prefered line enders
set ffs=unix,dos,mac
""Type :help ffs for more info, can be set in GVIM via options menu.
"enable filetype detection
filetype on
"turn off ft plugin and indent
filetype plugin off
filetype indent off

"Enable syntax highlighting
syntax on
"" Syntax highlighting is very good, does stuff like making comments blue, keywords green
"" strings red e.t.c. Very nice for markup, scripting, config files, and programming.

"""""""""""""""""""""""""""""""
" Keybindings
"""""""""""""""""""""""""""""""

"Use the ";" as a duplicate of ":" makes life so much easier
"for some odd reason it cannot be followed with a comment on it's line!
:nma ; :
"" I personally think typing ; instead of pressing shift + : is the way it should be

"F1 turns on spellchecking in current buffer
map :setlocal spell spelllang=en_us
"" I only want spell checking for certain files so this lets us turn it on when we want it
"" and just in the current buffer (like file)

"F2 turn on line numbering
map :set number
""I don't want line numbering unless it's a source file or a big document. Pressing this
"" key we turn it on when wanted.

"F10 rids us of ^M after carriage returns
map :%s/^M/ /g
""You have to make the ^M by pressing control+v control+m for this to work.
"" Some times you'll get pesky ^M at all the EOLs and it annoys me - strip them

"""""""""""""""""""""""""""""""
"User Interface Options
"""""""""""""""""""""""""""""""
"Always show the status bar with file name e.t.c.
set laststatus=2
"" 0=never, 1=only if more then one file/buffer/tab
"Show %of file remaining in statusbar
set ruler
"" I use thse two this b/c I like knowing what line/column I'm on un obtusivly + file name
"" and how far into the file overall I am.

"""""""""""""""""""""""""""
" MOUSE
"""""""""""""""""""""""""""
"Start with mouse support
set mouse=a
"Make pointer an I-Beam in insert mode
set mouseshape=i:beam
"Hide the mouse when typing text (GUI only)
set mousehide
"" I'm used to being able to scroll around with my mouse wheel :)
"" Try :help mouseshape to look at what you can do with the mouse pointer. X11 supports
"" more options then Windows.

"""""""""""""""""""""""""""""""
"General Preferences
"""""""""""""""""""""""""""""""

"Command history
set history=50
"" Remebers the last 50 commands entered via :command

"automatic re-reading of changed open files
"set autoread
"" Gotta test this, basically if you edit in vim and edit with another app. It will try
"" to re-read the file.

" Switch on search highlighting - use :noh to turn it off after a search
set hlsearch
""highlights all matches to a /search

"ingore case when searching
set ignorecase
"" just like grep -i "I guess"

"set cmd line size
set cmdheight=2
""This makes the command line at the bottom, where you see the ":" when entering commands
"" be 2 lines high. Not really important IMHO

__________________________________________________

Some changes I plan, if it’s starting with the GUI I’ll have it set it so I can right click on miss spelled words and correct them. you can move the cursor to the word and press z= for a list of corrections, and use ]s and [s to search forward/back. Some times I just scroll with the mouse when proof reading so this helps. You can do a :set “mousemodel=popup_setpos” to get it after you turn on spell checking. I want to set it up so I can quickly convert a files format between DOS and UNIX via F11 and F12, should be possible.

I’ve downloaded a few things from http://www.vim.org/scripts/ that I want to toy with. One was a pack of 140 themes for gvim gotta sort that hehee. Another was a Matrix screen saver. It’s pretty nice if you speed it up but on my system it makes me use like 50~60% CPU judging by GKrellm2 my favorite GTK Krell system monitoring app.

One of the reasons I love vim very much is it’s very relaxing to us. Since I play games often as I can get a good tactical one /w my team mates. I do plenty of running. Once the tangos know your there you gotta get moving quickly (Dynamic). So in the intertests of moving as fast as is safe and doing proper B and CB entries (Bang & Breach Bang clear). I have my pinky jutted out to hold shift many times. B/C Usually I don’t run all the time, I try to sneak about unless I plan on being Dynamic. So that and using my pinky to make capital letters puts alot of strain on my, now couple that with Escape Meta Alt Control Shift (EMACS) style editing. When I use my pinky to deal with capslock (hate that key), shift, control, z, and Windows. It’s nice not to have to strain my fingers or wrists. I find using vim very comfortable for long edits. It’s also so dang effective that I can’t stand many other editors. Its like the speed and power of Vi/Vim ruins you for other editors once you learn it. I don’t claim to be no Vim Master or any thing but to me its gotta be the worlds greatest editor. Vi is in the top 10 in my book but Vim >= #1 xD

The only bad thinkg is some times I press # instead of $. The $ key moves to end of line in normal/visual modes. While the * and # keys searches forward and backwards for the word under the cursor. One thing I’m looking at is a C Refernce that can be ran in Vim, might help me write files on Win32 again. Usually I prefer BSD for doing C work because I can quickly look up a routine via the system manual. After all Unix was written in C and so is largly FreeBSD and I’d reckon most of GNU/Linux which is infact made up of many languages afaik.

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 !!!