From owner-freebsd-questions@FreeBSD.ORG Fri Dec 26 08:34:39 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DB58B16A4CE for ; Fri, 26 Dec 2003 08:34:39 -0800 (PST) Received: from munk.nu (mail.munk.nu [213.152.51.194]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1252E43D3F for ; Fri, 26 Dec 2003 08:34:37 -0800 (PST) (envelope-from munk@munk.nu) Received: from munk by munk.nu with local (Exim 4.24; FreeBSD) id 1AZuuz-000Ljl-Pl; Fri, 26 Dec 2003 16:34:29 +0000 Date: Fri, 26 Dec 2003 16:34:29 +0000 From: Jez Hancock To: zhangweiwu@realss.com Message-ID: <20031226163429.GC75733@users.munk.nu> Mail-Followup-To: zhangweiwu@realss.com, freebsd-questions@freebsd.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i cc: freebsd-questions@freebsd.org Subject: Re: need learning direction suggestions on using editors X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Dec 2003 16:34:40 -0000 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 ' - 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 =expand("%:p:h") . "/" " map a toggle for pasting: :set pastetoggle= 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('') . " with:") :exe 'bufdo! %s/' . expand('') . '/' . s:word . '/ge' :unlet! s:word endfun map \r :call () map a=strftime("%c") " 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('') endfun map :call HelpOnWord() " 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('') " 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() -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