Firewalls posts about Editors got me to thinking. What are the coolest tricks you use with your editors? Like any vi tricks, emacs tricks, heck any 'edit' tricks? Anything that if you had to switch editors, the new editor would HAVE to be able to perform?

For me I run Linux and I'm a huge fan of vi's pattern matching.


Everyone has their demons....

Replies are listed 'Best First'.
RE: Editor tricks.
by clemburg (Curate) on Sep 30, 2000 at 16:41 UTC

    Some of the things I do regularly:

    • vi/emacs: filter parts of the edit buffer through commands (perl one liners, tools like fmt(1), specialized little tools for building indexes, cross-references, and the like ...)
    • vi/emacs: map a key to the compile command (or the respective vi macro) to run Makefile entries that do compilation, testing, publishing to web sites, ...
    • emacs: use the shell mode to record all your activities, e.g., when working as root on other's machines, or when doing a new installation routine, ...
    • vi/emacs: make the editor put in templates for common tasks
    • vim/emacs: develop your own, intelligent (for you) syntax colouring scheme
    • emacs: use the editor as shell substitution on platforms where you have no convenient shell (command line history, ...)

    Christian Lemburg
    Brainbench MVP for Perl

RE: Editor tricks.
by t0mas (Priest) on Sep 29, 2000 at 17:01 UTC
    Don't know how cool it is, but my .gvimrc is now full of snippets I've picked up form PM, like:
    inoremap <C-P>slurp @array=do{local @ARGV=$file;<>};<CR>
    giving me a file eater at Ctrl+P slurp. Power at your fingertips...

    /brother t0mas
Re: Editor tricks.
by stefan k (Curate) on Jul 26, 2002 at 06:52 UTC
    can't believe this thread slipped me for so long...
    Well, after some 6 years in (X)emacs and with a configuration of some 4000 lines of elisp I must have configured my XEmacs (almost) exactly to my needs. What is it that makes this so powerfull for me?
    • dabbrev (defaults to M-/): dynamic abbreviations which lets you pick the really long but insightful variable names because you don't have to type them anymore.
    • M-x locate so you'll never do the locate in xterm and mark the filename with the mouse again (later pasting that filename into XEmacs anyway)
    • speedbar one of the finest tools for navigation in large projects I've ever come across
    • desktop for re-opening all the files on the next day
    • active-menu.el (see the website) for one more line of code
    • function-menu for another navigation mechanism which works only in the current buffer (a buffer is usually a representation of a file in the editor)
    • saveplace to find myself at exactly the cursor position as the last time I opened that file
    • cperl auto help shows a short syntactic information; good if it has been a while since your last perl programm
    • and thousands of other things that don't spring to my mind in this moment
    Have fun!

    Regards... Stefan
    you begin bashing the string with a +42 regexp of confusion

RE: Editor tricks.
by runrig (Abbot) on Sep 29, 2000 at 22:53 UTC
    My favorite thing with vi is that I've set up the F1 and F3 keys so that if I have a block like this:
    select something
    from sometable
    where something="some_value"

    If I hit F1 while in the block, it pipes the contents of the block to sqlplus (Oracle SQL tool, it used to go to dbaccess, the Informix SQL tool), and creates a block below the current block with the results. That way I can edit any sql with vi, and all queries and results are immediately saved (temporarily at least in the current vi session).

    I have F3 set up to delete the block after the current block, so it makes for quick edit/execute/edit/execute cycles until I like the result.

    On any WinPC I'm forced to use, I usually install vim, because I can't stand Notepad. Though I've never implemented the above sort of system from a PC.
RE: Editor tricks.
by Corion (Pope) on Sep 29, 2000 at 17:22 UTC

    First of all, an editor needs a clipboard. I've learned the necessary tricks for Windows, pico and vi :

    • For Windows, it's CTRL-C, CTRL-V and CTRL-X
    • For pico, it's CTRL-K to erase a line and CTRL-U to paste a set of lines
    • For vi, it's dd to erase a line and p to paste it.

    The second nice-to-have thing is the ability to replay keystrokes. pico has no such capability, vi has limited capability by prefixing the number of repetitions to a single command, and the Borland IDEs and proton have that capability. notepad lacks that capability. D'oh.

    Syntax highlighting is nice eye-candy that helps immensely when doing some TeX stuff. Both, proton and nedit do that.

    Being able to read (and maybe write) both, Unix and DOS line endings is a sure plus, but not really necessary, as I can convert stuff using Perl anyway.

      vi and emacs both have named registers that you can use to store and recall text. I don't know how to use vi but I know they're there.

      • emacs does really beautiful rectangle cuts and pastes.
      • emacs does cuts, copies and appends to regisers.
      • emacs does cuts copies and appends to other buffers.
      • emacs lets you treat a register as a variable that you can increment and decremt and use it's value in keyboard macros.
      • emacs lets you write extra functions in lisp (if you want to)
      • emacs lets you record keyboard macros. either one time quick hacks or you can name them and bind them to a key. just for this session or make them permenant.
      emacs does lots of other wonderful things that I can't/haven't figured out how to do in vi. emacs figures out the line ending and uses it transparently, if it gets it wrong you can override it.


        nuance: "vi and emacs both have named registers that you can use to store and recall text. I don't know how to use vi but I know they're there."

        Hitting the double quote in command mode tells vi that the next letter you enter is going to be the name of the buffer that you'll be refering to. For instance:


        will cut everything from the cursor to the end of the line, and throw it in buffer a. To paste it in again, you'd say:


        The :map command binds a key to a macro... like so:

        :map q xp

        which will make the q key cut the letter the cursor's presently on and paste it after the next one, effectively transposing them.

        Some of the other things you mention make me think. It's about time I went back and learned some more stuff, to make my editing more pleasant. It's easy to just roll along after a certain point, using what you know.

(Dermot) RE: Editor tricks.
by Dermot (Scribe) on Sep 29, 2000 at 17:53 UTC
    In Emacs or XEmacs, M-q is fill-paragraph-or-region. It properly formats the current paragraph. You live without it, you learn it. Suddenly, you can't live without it.
RE: Editor tricks.
by AgentM (Curate) on Sep 29, 2000 at 18:54 UTC
    hey emacs guy, you're forgetting the cool split window stuff you can do. (same window, up to 5 files open). I use this alot to scan documentation and program in the same terminal. (C-x-1 reduces ya back to one and juts open a file to have the window split. This is the same thing that happens when you activate the help.)
    AgentM Systems or Nasca Enterprises is not responsible for the comments made by AgentM- anywhere.
      I use vi, vim and Xemacs mostly. In windows I use Notepad just because it's there. I don't use windows for anything bar playing the odd game so I don't have to do any heavy work in it. The posts about Notepad+ caught my eye though, I'll check it out.

      With regards to editors under unix, I have long tried to stay away from the religious aspect of it although I think the flame fests can be funny they are getting a little tiring. Not that anything I think is going to stop history repeating itself. Many of the new college graduates I've worked with arrive into the company not really caring what they use but within weeks they are either raving vi nuts or raving emacs nuts. It's a cultural marker I suppose.

      I use vi or vim for system administration type work and for writing small bits of noddy code like the average perl script you see posted around here. For serious, project work, tracking down bugs in large collections of software or anything else of that nature I use emacs. I learn something new about emacs every now and again, it doesn't give up it's secrets too easily. Many would hate it for that. I love it for that. Why ? Well here are just a few of the reasons.

      1. Elisp. Imagine having an editor where you could write little pieces of Perl, name these functions and run them at will against the text in your editor. Thats what Elisp gives you in emacs.
      2. VM. Exactly the same environment for my mailer as for my editor. That's because my editor is also my mailer. Many have moved on to Mutt. Off with them I say. There's something soothing about being able to use the same keystrokes and functions in multiple applications. This extends I suppose to all applications that use the readline library including bash itself. I don't have access to a news-feed except for Deja but if I did I would use emacs for that too.
      3. M-q fill-paragraph. I mentioned this one in a previous post. There's nothing magical about it but it makes my life easier. Fscks up mightily on troff and other formats where there are no blank lines between paragraphs but everything has got its limitations, right ?.
      4. re-search-forward, re-search-backward. I don't have to tell Perl coders how useful being able to search for regexes is. The elisp regex flavour is ugly compared to Perls but it is basic and once you get over the leaning toothpick syndrome it's not too bad.
      5. BBDB. The Big Brother Database. Sits at the bottom of your VM frame in a separate window and it scans emails as they come in talking out names, alternate email addresses. Very useful, you soon build up a database of names, email addresses, phone numbers and addresses and half the time you don't even see it happening.
      6. Consistency. C-f goes forward a character, M-f goes forward a word. In the various programming modes they will go forward something equivalent, usually an expression instead of a word.
        Among my personal favoutite things about emacs are
        • the query replace functions
        • ediff (I can't say eough good things about this) - lets you do interactive diffs/merges on 2 or three files. Diffs are shown in different colors.
        • the comment aligning functions in most programming major modes. M-;
        • the way the tab key works. In text mode it aligns to the start of words in the line above, which makes colums really easy to do. In most programming modes it reindents the curent line. And it always does consistant formatting of the white space when you hit the tab key (i.e. it converts as many spaces at the begining to tabs as possible and fills the rest with space characters.
        • You can convert all tabs to spaces if you want
        And various other wonderful things too numerous to mention here.


        I know this is a bit late, but I just found this thread. :)

        Quoth Dermot:

        Imagine having an editor where you could write little pieces of Perl, name these functions and run them at will against the text in your editor.

        With Vim with Perl compiled in, you can do exactly that. With Perl. It's pretty slick.

        Black flowers blossum
        Fearless on my breath
        Teardrops on the fire
        Fearless on my breath