LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   How do I use macros with X11 editors? (https://www.linuxquestions.org/questions/linux-desktop-74/how-do-i-use-macros-with-x11-editors-518686/)

Soabirw 01-12-2007 11:01 AM

How do I use macros with X11 editors?
 
I'm trying to do some basic macros to format text. For example, I have a list of names and I want to put them in single quotes and comma separated. In my Windows and OS X editors I would just go to some Macros menu and Start Record, do the necessary keystrokes, Stop Record, then playback as needed. That's ideally what I would like to do in editors like gEdit,Kwrite,etc. Right now I'm having to bust out Vim and do something like, :map g i'<End>',<Del><Esc>l

Fine tuning a macro that way is a little more time consuming then I would like, especially for the more complicated macros. Any suggestions?

Eric

Simon Bridge 01-13-2007 04:06 AM

gEdit plugin: snippets - will assign a string to a set of keystrokes (and a context).

search and replace will help with your specific example - you want to replace each newline (\n) with a single quote, followed by a comma, followed by a space, followed by a single quote (,' ,).

Different systems will have different preferred methods for this (i.e. Emacs).
You can especially have a lot of fun with macros in LaTeX.

jschiwal 01-13-2007 04:35 AM

From your description, it sounds like using a regular expression in a substitute command would work out better.
You can precede the "s" command with the range to operate on--
"%s" operates on the entire file. "10,30s" works on lines 10-30. You can save parts of the line that match a pattern using storage registers.
:%s/\([A-Z][a-z]*\) \([A-Z][a-z]*\) /\2, \1/

This will take a list of names like
John Smith
Jane Doe
And convert it to
Smith, John
Doe, Jane

Soabirw 01-13-2007 10:27 AM

I'll play around with those gEdit plugins, thanks.

I'm sure regular expressions will do most of what I need, they are ver powerful after all. But I have yet to really wrap my head around them. I prefer the macro way because it only takes a few seconds to setup, where it can take me a good 20 minutes to hammer out a regular expression. But maybe this will be a good way to finally beat them into my head. ;)

dolsson5 01-16-2007 08:24 PM

emacs
 
Emacs has easy macro record and playback. Don't be frightened of emacs. It's horribly powerful, but the easy stuff is still easy. It's window isn't as pretty as the newer GUI guys, but it's way more powerful and mature.

Start recording: ctrl+x (

End recording: ctrl+x )

Execute recorded macro: ctrl+x e

Soabirw 01-17-2007 09:58 AM

Thanks, I'll give that a try. I remember a few years ago bouncing between emacs and vim. I liked both for different reasons, but stuck with vim. Of course, this was on the shell. I've never really played with their X11 versions. So I'll give that a try.


All times are GMT -5. The time now is 06:20 AM.