Thursday, March 12, 2015

Console editor with Notepad behavior

When I started using Linux (it was Ubuntu in 2007), I wanted a console text editor which would support keyboard shortcuts used in Windows Notepad:

- Ctrl + Left/Right -- go to the beginning/end of the previous/next word
- Ctrl + Home/End -- go to the beginning/end of the file
- Shift + Left/Right -- select previous/next character
- Control + Shift + Left/Right -- select previous/next word
- Control + Shift + Home/End -- select line to the beginning/end
- Control + C/V/X/Z -- copy/paste/cut selected text, undo last operation

Nano, which is present in Ubuntu out of the box, is quite simple, but doesn't support almost all of the shorcuts.

Vim -- I didn't like it immediately -- I even didn't know to close it.

Emacs -- I could not exit it either, but I liked it more.

In the end I stopped looking and used what I have -- Vim/Emacs/Nano.

But today I found out that Emacs starting with version 22.1.1 has Cua mode.
The command M-x cua-mode sets up key bindings that are compatible with the Common User Access (CUA) system used in many other applications.
Add this to `~/.emacs`:

(cua-mode t)
(setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour

and it works!

Be aware that Emacs has its own clipboard, and Ctrl+V will not paste system clipboard contents.

No comments:

Post a Comment