need learning direction suggestions on using editors

Jez Hancock jez.hancock at munk.nu
Fri Dec 26 08:34:40 PST 2003


On Thu, Dec 25, 2003 at 04:48:11PM +0800, Zhang Weiwu wrote:
> Hello. I have been using the vi that comes with FreeBSD for more than a 
> year. I now can manage to use lots of vi features except the tag mode which 
> I don't know clear about its concept (perhaps because of my bad English).
> 
> Now I think vi is not sufficient. I hate to type "!perl %" each time I edit 
> and re-try my perl script, and I'd like to load related files quickly. (say 
> load a included php file when I see it is being included.)
> 
> Should I advance to vim right now or emacs, or is it that I didn't dig into 
> vi deep enough to release its full power? I wonder how many programmers are 
> still using 4BSD vi (compare to enchanced vi's)? Maybe none? Maybe many?
> I know very few about editors other than vi, if I'm going to learn another 
> editor now, I wish I can be using that forever, and I wish the editor have 
> good L10N (esp. Chinese). I do some Java program, php and perl program but 
> not C, and I'd likely to do these kind of program in the coming years, so 
> what is the best editor for my kind?
The major benefits of vi over vim are multiple buffers and the concept
of windows.  A buffer allows you to load more than one file into vim at
a time and you can then view those other files in other 'windows'.

For example if I type a filename such as /usr/ports/editors/vim/Makefile
and then place the cursor over a part of the filename above and hit
'gf', vim will open the Makefile for vim! 

I can then switch back to this buffer by hitting 'ctrl-^'.

You can also edit whole directories at once in this way (read only
though) - this is more useful if, say, you know that a file exists in a
certain directory but you don't remember exactly what the file is called
:P

To create a new 'window', you hit 'ctrl-w n'.  You can then open a
buffer in that new window by typing ':bn' in command mode, where 'n' is
the number of the buffer you want to open. 

Another great feature is 'visual' mode - hitting 'V' in command mode
switches into visual line mode and allows you to select complete lines
of text.  Hitting 'v' in command mode takes you into visual mode so you
can highlight and select text per character.  There's also 'visual
block' mode, which allows you to select vertical blocks of text - you
enter visual block mode by hitting 'ctrl-v'.


There are a lot of other great features such as tab completion for
completing filenames and vim commands and too many other numerous things
to mention here!

In summary, if you already know vi commands then vim should be great for
you.

To learn more about vim I found the vim website very useful - especially
the 'vim tips' section where you can read about lots of useful vim stuff
- the vimtips page is here:

http://www.vim.org/tips/index.php

One of the first things to do if you decide to switch to vim is to get a
decent ~/.vimrc file set up.  I'll include mine here since it has lots
of comments - to find out more info about each command type ':help
<command>' - ie ':help wmnu' to learn about the wildmenu command

Good luck :)

My ~/.vimrc file is here:

-snip-
" Do syntax highlighting:
syn on

set autoindent
set tabstop=4

" keep a longer history list than usual - may want to change this if
" things seem slow in vim:
set history=1000
set ignorecase
set shiftwidth=4

" shows the current command in the status line:
set sc

" 'wildmenu' allows you to open new files with tab autocomplete on:
set wmnu

" nice status line
set ls=2
set ruler

set comments=b:#,:%,fb:-,n:>,n:),sr:/*,mb:*,ex:*/,b://

" This is important for ease of use of buffers/windows:
set hidden

" Set 'g' substitute flag on.
set gdefault

" keeps cursor in middle of screen
set scrolloff=9999

" set vim to use 'short messages'.
set shortmess=at

" showmatch: Show the matching bracket for the last ')'?
set showmatch

set background=dark

" prompt for confirmation before quitting:
set confirm

" Last Modified file path (hit ,e)
map ,e :e <C-R>=expand("%:p:h") . "/" <CR>

" map a toggle for pasting:
:set pastetoggle=<F12>

set textwidth=72

" a search and replace function - with cursor on a word, hit
" '\r' to search/replace all instances of that word in the document:
fun! ()
    let s:word = input(" " . expand('<cword>') . " with:")
    :exe 'bufdo! %s/' . expand('<cword>') . '/' . s:word . '/ge'
    :unlet! s:word
endfun
map \r :call ()<CR>
map <F2> a<C-R>=strftime("%c")<CR><Esc>

" function to provide help on a vim command.  Hit 'F1' when on a word in
" a document to view the vim help file for that command
fun! HelpOnWord()
	:exe ':help '.expand('<cword>')
endfun
map <F1> :call HelpOnWord()<CR>

" Function to autoopen the manpage of a word the cursor is on; hit 'K'
" when on a word to use.
fun! ReadMan()
	" Assign current word under cursor to a script variable:
	let s:man_word = expand('<cword>')

	" Open a new window:
	:exe ":wincmd n"

	" Read in the manpage for man_word (col -b is for formatting):
	:exe ":r!man " . s:man_word . " | col -b"

	" Goto first line...
	:exe ":goto"

	" and delete it:
	:exe ":delete"

	" finally set file type to 'man': 
	:exe ":set filetype=man" 
endfun

" Map the K key to the ReadMan function:
map K :call ReadMan()<CR>
-snip-

-- 
Jez Hancock
 - System Administrator / PHP Developer

http://munk.nu/
http://jez.hancock-family.com/  - personal weblog
http://ipfwstats.sf.net/        - ipfw peruser traffic logging


More information about the freebsd-questions mailing list