LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-16-2014, 02:12 PM   #1
thriftee
Member
 
Registered: Jan 2009
Posts: 42

Rep: Reputation: 2
Need help remapping keys for copy/paste in EMACS


Once upon a time I had DOS and a great editor called Brief, and I was able to write all sorts of nifty macros.

Ok, today, I'm trying to do some coding under linux, and I've got a few hundred lines of text menu structures that I need to convert to an xml menu structure.

First problem is my copy and paste keys are a nightmare. They used and odd key combination for each, so I keep screwing it up. I found a place where it says it will change it to normal CUA standard, Ctrl-C and CTRL-V but it doesn't work. Does anyone know how to get this to work?

Thanks much
 
Old 12-16-2014, 02:25 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
I know Emacs has a Brief emulation mode (no idea how good it is, I never used Brief). To enable M-x brief-mode RET (meaning hit Alt+X, then type brief-mode then hit <enter>).

M-x cua-mode RET should bind Ctrl+C to copy but only while there is an active region (aka selection). Otherwise it retains the normal Emacs meaning.

Also, note that if you run Emacs in a terminal, some keybindings can't be recognized, e.g. the terminal sends the same code for Ctrl+M as <enter>, so there is no way to distinguish between them in terminal mode.
 
Old 12-16-2014, 02:52 PM   #3
thriftee
Member
 
Registered: Jan 2009
Posts: 42

Original Poster
Rep: Reputation: 2
Hmmmm,


Thanks much for the quick response.

I reprogrammed most of the Brief keyboard, so I am not really wanting their layout... But I will certainly try it to find out.

I did find a place to change the copy/paste, but it didn't have any effect, and the keys still don't work, so I am forced to use the mouse.

Is there a file of key mappings that you can just change like there was with Brief?

Thanks again...
 
Old 12-16-2014, 03:19 PM   #4
thriftee
Member
 
Registered: Jan 2009
Posts: 42

Original Poster
Rep: Reputation: 2
I tried brief-mode, but its lost other keys that I need and I don't know how to see, change or create the key maps.

How can I get brief-mode turned off, please?
 
Old 12-16-2014, 03:27 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Quote:
Originally Posted by thriftee View Post
I did find a place to change the copy/paste, but it didn't have any effect, and the keys still don't work, so I am forced to use the mouse.
"Options" > "Use CUA Keys" ? Works for me.

Quote:
Is there a file of key mappings that you can just change like there was with Brief?
Not exactly, you can execute (emacs) lisp expressions to update the keymap(s). For example make Ctrl+V be paste:
Code:
(define-key global-map (kbd "C-v") 'yank) ; yank is what Emacs calls paste
The file ~/.emacs.d/init.el is executed on startup. You can also execute expressions at run time with M-: (Alt+Shift+;).

But there are a lot of important keybindings on C-x, and C-c so it's not really a good idea to override those (eg save is on C-x C-s). The builtin cua-mode allows the familiar Ctrl+Z,X,C,V while keeping the normal Emacs bindings for other times.

Quote:
How can I get brief-mode turned off, please?
Code:
M-: (brief-mode -1) RET
You can show the current keybindings with <f1> b (but that doesn't work in brief-mode because it overrides <f1>).
 
1 members found this post helpful.
Old 12-16-2014, 03:40 PM   #6
thriftee
Member
 
Registered: Jan 2009
Posts: 42

Original Poster
Rep: Reputation: 2
Ok, thanks much.

I got it into CUA mode and the copy/paste keys aren't right up on the menus but they work correctly now.

I couldn't get the record and playback to work though because I can't figure out how to search, then start marking on the next character, then search for the end marker, back off 1 character, and copy from mark to mark, then switch buffers and paste. In Brief I think they called it "drop anchor"...

Oh well. I can probably do it by hand in 6 or 8 hours. It would have been 5 min in Brief.
 
Old 12-16-2014, 03:51 PM   #7
thriftee
Member
 
Registered: Jan 2009
Posts: 42

Original Poster
Rep: Reputation: 2
And thanks for at least getting me to where I can copy/paste. The other editors I tried didn't have multiple windows and buffers, so were quite painful to use trying to edit 3 files at once like this for hundreds of lines.
 
Old 12-16-2014, 04:07 PM   #8
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Quote:
Originally Posted by thriftee View Post
I got it into CUA mode and the copy/paste keys aren't right up on the menus
Oh I see, that's probably because of the way C-x and C-c are made to do double duty as I mentioned before.

Quote:
I couldn't get the record and playback to work though because I can't figure out how to search, then start marking on the next character, then search for the end marker, back off 1 character, and copy from mark to mark, then switch buffers and paste. In Brief I think they called it "drop anchor"...
In Emacs, completing a search pushes a "mark" where the search started. So I think the equivalent would be something like (where begin and end are the starting and ending delimiters respectively):
Code:
C-s begin RET
C-s end RET
C-b ; or <left>
C-u C-x C-x ; this activates region, only needed in CUA mode
C-c
C-x b other buffer name RET
C-v
Quote:
Oh well. I can probably do it by hand in 6 or 8 hours. It would have been 5 min in Brief.
I'm sure it's possible to the task as fast in Emacs, but it may take a while to learn how.

Last edited by ntubski; 12-16-2014 at 04:08 PM. Reason: colour comments in green
 
1 members found this post helpful.
Old 12-16-2014, 05:38 PM   #9
thriftee
Member
 
Registered: Jan 2009
Posts: 42

Original Poster
Rep: Reputation: 2
Yes, I'm sure you are right there. It takes forever to do things when you don't know what you are doing and working in unfamiliar tools, but eventually you can get good at them if you are able to get yourself to keep trying.

I definitely haven't seen anything else better in the linux world, as far as being customizable, but its just not good trying to learn how to drain swamps when you are up to your elbows in alligators.

Thanks for the help. I wish I could have found that, but I'd never have guessed to be looking for "yank".
 
Old 12-16-2014, 10:30 PM   #10
thriftee
Member
 
Registered: Jan 2009
Posts: 42

Original Poster
Rep: Reputation: 2
I did find the key map under "Describe". I should be ok with it once I get used to it. It actually looks like Brief was patterned after it. I think I read that someplace once upon a time.
 
Old 12-17-2014, 09:53 AM   #11
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Quote:
I definitely haven't seen anything else better in the linux world, as far as being customizable,
Emacs is probably the most customizable editor anywhere. The other major editor in the Linux world would be vim, which I have seen cited as requiring less customization than Emacs. I think vim's keybindings are as hard or harder to learner than Emacs' though[1]. When I started out, I alternated running the Emacs and vim tutorials until the Emacs keybindings "clicked" for me. You might find the Emacs tutorial helpful (<f1> t, or under the "Help" menu), although it's not written with CUA mode in mind.

[1]: see also Editor Learning Curves (vi is a precursor to vim)
 
Old 12-17-2014, 10:10 AM   #12
thriftee
Member
 
Registered: Jan 2009
Posts: 42

Original Poster
Rep: Reputation: 2
This is sad, but I was sitting here thinking of firing up one of my old pre-windows computers and copying Brief to floppy with all my key mapping and such, and seeing if it would work under wine.

But the more I think about it, it would have problems with things like long filenames, if I recall correctly, so maybe its time to learn something new...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remapping keys that generate multiple scan codes moonwalker Linux - Laptop and Netbook 1 02-07-2014 11:39 AM
remapping keys hashbang#! Linux - Newbie 12 02-02-2012 05:21 PM
Changing the keyboard keys (that is, remapping them). stf92 Linux - General 7 06-10-2010 01:02 PM
Copy and Paste problem in emacs on Fedora 4 yinglcs Linux - General 3 01-20-2006 01:19 PM
Remapping keys - is it possible? LooseCanon Linux - General 2 09-03-2003 10:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration