help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hard to switch from vi


From: Pascal Bourguignon
Subject: Re: Hard to switch from vi
Date: Mon, 09 Oct 2006 04:04:43 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Wen Weng <WenWeng@charter.net> writes:

> Hi, I am a vi user for years and am now trying emacs.
> I find it hard to get efficient. Can someone teach me some
> commands?

Emacs can do it itself.  The first thing emacs does, when you start
it, is to display a screen that says:

Welcome to GNU Emacs, one component of the GNU/Linux operating system.

Get help           C-h  (Hold down CTRL and press h)
Emacs manual       C-h r
Emacs tutorial     C-h t           Undo changes     C-x u
Buy manuals        C-h C-m         Exit Emacs       C-x C-c
Browse manuals     C-h i
Activate menubar   F10  or  ESC `  or   M-`
(`C-' means use the CTRL key.  `M-' means use the Meta (or Alt) key.
If you have no Meta key, you may instead type ESC followed by the character.)



Then, type CTRL-h and t to get the tutorial that will teach you the
basics. 


> 1. In vi, to delete a line, I do, "dd" and to delete 5 lines, I do
> "5dd". In emacs, how do I delete a complete line? C-k only delete
> from cursor to the end of line. Adding a C-a is really too much work.

C-k  
C-k C-k 

M-5 C-k
C-u 5 C-k
C-5 C-k   ; on X 


> 2. Is there a repeat last command command like the dot command in vi?

No.   But you can repeat any command by prefixing it with
M-<digit>...  or C-u <digit>...

If you have a group of commands that you might want to repeat, you can
put them in a "keyboard macro", and invoke the keyboard macro.

Type: M-x apropos RET kbd-macro RET


> 3. In vi, to find a pairing brace I use the "%" command, is there a
> command like thins in emacs?

C-c , and C-c .   (backward-sexp and forward-sexp)

Also, you can set the variable blink-matching-paren to true to have
the pairing brace be highlighted automatically when the cursor passes
over one of them.

M-x set-variable RET blink-matching-paren RET t RET

Or type in the *scratch* buffer:

(setq blink-matching-paren t) C-x C-e

If you want it always on, you can put the form:

    (setq blink-matching-paren t)

in your ~/.emacs file.


Also, most of the time you don't need to identify manually the
matching parenthese, because you can manipulate the parenthesized
blocks as wholes, using commands such as  kill-sexp (C-M-k).

Imagine I want to exchange the then and else branches:

       if(a==b){
           printf("no");
           a++;
       }else{
           printf("yes");
           b--;
       }

I move on the first {, and type C-M-k

       if(a==b)else{
           printf("yes");
           b--;
       }

then I move forward one word with M-f to reach the remaining {, and
type C-y to yank the first branch there:

       if(a==b)else{
           printf("no");
           a++;
       }{
           printf("yes");
           b--;
       }


and I type C-M-K to kill the else branch, and type C-u 2 C-c ,
to move at the beginning of the else.

       if(a==b)else{
           printf("no");
           a++;
       }

then I type C-y to yank the else branch:

       if(a==b){
           printf("yes");
           b--;
       }else{
           printf("no");
           a++;
       }

There are also specialized minor mode to do even more structuring
editing with some languages, like paredit-mode for lisp and scheme,
where even more low level editing is done automatically.



> 4. Should I really need to switch to emacs?

This is highly advised.   


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]