News for hackers. Stuff that matters.
Re:Vim's 25th anniversary and the release of Vim 8 by a-b on Thursday February 09, 2017 @11:24AM (#13608037)
Fun fact about vim:

When vi was originally designed the most popular keyboard was ADM-3A and later IBM XT https://en.wikipedia.org/wiki/IBM_PC_keyboard#/media/File:IB... The layout of this keyboard has Control on the place where modern keyboards have a CapsLock key. Naturally that's why vi and vim was meant to use CTRL-[ to exit to the normal mode.

25 years later Apple introduced ToughBar and made ESC key virtual. As result remapped CapsLock-[ make sense again ;)

edit: Add ADM-3A keyboard

Re:Vim's 25th anniversary and the release of Vim 8 by kps on Thursday February 09, 2017 @11:39AM (#13608208)
> when vi was originally produced most popular keyboard was IBM XT.

Probably not, since the IBM XT was five years in the future.

The canonical vi keyboard is the ADM-3A. http://terminals-wiki.org/wiki/index.php/File:Lear_Siegler_A... Escape is almost as accessible as Control.

The ADM-3A also explains why shells use ‘~’ to represent the home directory.

Re:Vim's 25th anniversary and the release of Vim 8 by ntumlin on Thursday February 09, 2017 @11:57AM (#13608433)
I was curious about some keys I hadn't seen before, so for anyone curious, here's the purpose of the "rub" and "here is" keys (from the ADM-3A operators manual[0] page 3-7 and 3-8):

RUB. When the RUB (rubout) key is typed while holding down the SHIFT key, a non-displayable rubout code (ASCII DEL) is transmitted to the computer. The cursor is not advanced and the character code stored in display memory is not overwritten. RUB is normally used to tell the computer that a previous character should be deleted.

HERE IS. If the Answer Back option is installed, typing this key transmits an identification message (stored in a special ADM-3A memory) that identifies the terminal and alerts the host computer that a message is to follow. If no Answer Back option is installed, the key has no function.

[0] http://www.classiccmp.org/dunfield/altair/d/adm3a.pdf

Re:Vim's 25th anniversary and the release of Vim 8 by kps on Thursday February 09, 2017 @12:30PM (#13608815)
For the reason DEL is shifted ‘_’, see your friendly neighbourhood ASCII table, and/or one of the recent HN threads¹. The ADM-3A² is a good example of a bit-paired keyboard³.

¹ https://news.ycombinator.com/item?id=13539552

² https://en.wikipedia.org/wiki/ADM-3A

³ https://en.wikipedia.org/wiki/Bit-paired_keyboard

Re:Vim's 25th anniversary and the release of Vim 8 by a-b on Thursday February 09, 2017 @11:45AM (#13608288)
You're right, thanks for your correction. My main point was a location of the Control key. I guess with IBM XT keyboard CTRL-[ become a most reasonable option https://en.wikipedia.org/wiki/IBM_PC_keyboard#/media/File:IB...
Re:Vim's 25th anniversary and the release of Vim 8 by rthomas6 on Thursday February 09, 2017 @06:15PM (#13611939)
Also notice the arrows on H J K L.
Re:Vim's 25th anniversary and the release of Vim 8 by WildUtah on Thursday February 09, 2017 @09:21PM (#13612806)
Promoting bad habits. Don't use the left-right arrow keys to move around!
Re:Vim's 25th anniversary and the release of Vim 8 by theviajerock on Friday February 10, 2017 @06:59AM (#13614767)
The left - right with the H J K L keys? Or the normal Keys ? And why is this a bad habit?
Re:Vim's 25th anniversary and the release of Vim 8 by WildUtah on Friday February 10, 2017 @11:20AM (#13616454)
Moving around with hjkl is a bad habit to be discouraged. It's not the vi way.

Well, j and k are fine if you're not moving far. A lot of slow scrolling up and down should be { and } or C-d and C-u or <count>[jk]. Even better: Use / and ?. It's bad to be repeatedly tapping j and k or waiting for the keys to repeat.

But h and l are the EMACS approach. You should be moving in a line with w, e, b, f, F, t, T, ^, $, I, A, 0, and the like. Vi provides lots of tools for efficient line editing and h and l are not good.

Beginners should try

    :noremap h <nop>
    :noremap l <nop>
to keep them from the temptation of the nefarious h and l keys.

Lately I use

    :no h ^
    :no l $
which is even better because ^ and $ require moving your hands off the home row even though they're much better than h and l for you.
Re:Vim's 25th anniversary and the release of Vim 8 by falcolas on Friday February 10, 2017 @12:44PM (#13617255)
Huh. The "vim way" goal posts have moved even further. Used to be "no-op your arrow keys and use hjkl", now it's "noop your hjkl keys".

Something I, as a dedicated VIM user, will never do. 'hjkl' work fine, and are a good addition to 'we{}$0' and so forth. I can't personally find the value of hobbling myself for the sake of meeting someone else's definition of the ideal user.

I even occasionally use the arrow keys. Heresy, I know.

Re:Vim's 25th anniversary and the release of Vim 8 by flukus on Thursday February 09, 2017 @09:38PM (#13612861)
> The ADM-3A also explains why shells use ‘~’ to represent the home directory.

Is that also the origin of '^' being start of line in a regex?

Re:Vim's 25th anniversary and the release of Vim 8 by kps on Thursday February 09, 2017 @11:49PM (#13613297)
Good guess, but no. The ADM-3A dates to 1976, but the regular expression syntax is definitely earlier: https://www.bell-labs.com/usr/dmr/www/qedman.html
Re:Vim's 25th anniversary and the release of Vim 8 by j-pb on Friday February 10, 2017 @07:20PM (#13620123)
Wow this is a better and cleaner/streamlined keyboard layout than I have on my 2015 MacBook Pro :(
Re:Vim's 25th anniversary and the release of Vim 8 by cseelus on Thursday February 09, 2017 @11:35AM (#13608146)
Actually I have remapped Caps-Lock to ESC and when pressed longer than a few ms to Ctrl system wide for years, with the Karabiner app.

I read about that neat productivity boost that also reduces the strain on your left hand a lot in a blogpost which "sold" this idea as "this is how VIM was intended to work" and I really love it. Useful even for normal terminal combos like Ctrl+C.

Only downside is, once you get used to it, you just can't go back ;-)

Re:Vim's 25th anniversary and the release of Vim 8 by tnorthcutt on Thursday February 09, 2017 @12:53PM (#13609062)
Sadly on macOS Sierra, you have to use Karabiner-Elements, which doesn't (yet, I hope) include support for long-press=ctrl.
Re:Vim's 25th anniversary and the release of Vim 8 by The_Hoff on Thursday February 09, 2017 @02:20PM (#13609952)
If you're fine giving up caps lock, Sierra makes it easy to remap caps lock to esc in Systems Preferences (it even disables the little green light on the key)
Re:Vim's 25th anniversary and the release of Vim 8 by ikurei on Friday February 10, 2017 @05:29AM (#13614454)
Sadly, that isn't as powerful as what our comment-ancestors do with Karabiner. Such an accessible and prominent key as Caps Lock is, IMHO, wasted if only used for ESC; using it both for Control when in combinations and ESC when alone makes the most sense.

I use Caps Lock for Cmd or Ctrl, depending on which keyboard I'm using, and <Leader><Leader> for Escape on Vim.

I don't know where I got this idea from, but I also use <Leader>w to exit to normal mode and save. It's so ingrained in me, that when I use other editors very often I have "Unexpected token" errors because of a ",w" in the middle of the code.

Re:Vim's 25th anniversary and the release of Vim 8 by toxik on Thursday February 09, 2017 @08:55PM (#13612696)
Wow, that's news to me! How I've waited for Apple to do this. Karabiner-Elements does some shady stuff with the kernel and in my experience makes the machine a lot less reliable.
Re:Vim's 25th anniversary and the release of Vim 8 by steeef on Thursday February 09, 2017 @11:47PM (#13613288)
There is a pull request to implement this feature: https://github.com/tekezo/Karabiner-Elements/pull/247

I haven't tried it myself. Honestly it's one of the things keeping me from upgrading to Sierra. Need to test it out first.

Re:Vim's 25th anniversary and the release of Vim 8 by drewm1980 on Friday February 10, 2017 @03:12AM (#13613956)
I am surprised to learn that the set of people who use vim and the set of people who have patience to "long-press" intersects!
Re:Vim's 25th anniversary and the release of Vim 8 by yankcrime on Thursday February 09, 2017 @03:30PM (#13610640)
FWIW you can also use Keyboard Maestro to solve this problem.
Re:Vim's 25th anniversary and the release of Vim 8 by innocentoldguy on Saturday February 11, 2017 @01:56AM (#13621491)
I use Keyboard Maestro for exactly this purpose. For the most part, it is great. However, it does just stop working every now and then, at least for me, which is mildly irritating.
Re:Vim's 25th anniversary and the release of Vim 8 by falcolas on Friday February 10, 2017 @12:45PM (#13617269)
> once you get used to it, you just can't go back

So true. So many capital letters typed and deleted.

Re:Vim's 25th anniversary and the release of Vim 8 by Something1234 on Thursday February 09, 2017 @10:26PM (#13613001)
Any way to do the remap with Gnome on Linux?
Re:Vim's 25th anniversary and the release of Vim 8 by c94o8e on Thursday February 09, 2017 @10:42PM (#13613048)
gnome-tweak-tool --> Typing --> Caps lock key behavior --> (near the bottom) select the swap option
Re:Vim's 25th anniversary and the release of Vim 8 by bryogenic on Thursday February 09, 2017 @02:02PM (#13609784)
Also worth noting: Ctrl+[ = ESC in ASCII, which is where the keyboard shortcut comes from.

https://garbagecollected.org/2017/01/31/four-column-ascii/

Re:Vim's 25th anniversary and the release of Vim 8 by inlineint on Friday February 10, 2017 @03:56AM (#13614143)
And it is processed not by Vim itself, but by the terminal emulator that sends Esc character to Vim. So the shortcut Ctrl+[ was not invented by vi author, but is a consequence of using Esc to exit from the edit mode.
Re:Vim's 25th anniversary and the release of Vim 8 by pvg on Thursday February 09, 2017 @02:19PM (#13609944)
That's fun but not a 'fact'. The ADM-3A keyboard had an 'ESC' key and it was positioned right where the tab key is typically today. Very easy to hit.

Here's a write up with nice pictures.

http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys...

Re:Vim's 25th anniversary and the release of Vim 8 by MichaelGG on Thursday February 09, 2017 @12:46PM (#13608988)
Why does a combo with two keys on opposite sides of the keyboard make sense? Surely something that can be hit with one hand is easier?

I'll have to try this for a week.

Re:Vim's 25th anniversary and the release of Vim 8 by highwind on Thursday February 09, 2017 @12:51PM (#13609048)
I personally find using two hands for pressing key combinations more comfortable than holding a modifier key with a pinky and reaching for the other key.
Re:Vim's 25th anniversary and the release of Vim 8 by nilved on Thursday February 09, 2017 @01:43PM (#13609602)
Right, but wouldn't you prefer using one key?
Re:Vim's 25th anniversary and the release of Vim 8 by bryogenic on Thursday February 09, 2017 @02:01PM (#13609773)
Re:Vim's 25th anniversary and the release of Vim 8 by freehunter on Thursday February 09, 2017 @11:13PM (#13613164)
Back then there was no mouse so both of your hands were on the keyboard full time. If you have two hands, it's a shame not to use them both.
Re:Vim's 25th anniversary and the release of Vim 8 by lytedev on Thursday February 09, 2017 @11:43AM (#13608268)
Why not use "jk" or "jj"?
Re:Vim's 25th anniversary and the release of Vim 8 by jcl on Thursday February 09, 2017 @02:23PM (#13609982)
These can be convenient if you are only entering text manually. But remapping regular -- albeit rare -- text sequences can have unexpected results when pasting copied content into insert mode in a terminal window. I've been bitten by this a couple times when pasting base64-encoded data.
Re:Vim's 25th anniversary and the release of Vim 8 by nick_g on Thursday February 09, 2017 @02:33PM (#13610087)
This has caught me as well, but it can be avoided by using `:set paste!` to toggle paste mode before pasting. This isn't something I need to worry about often enough but you can map that command if pasting external content is something you do often.
Re:Vim's 25th anniversary and the release of Vim 8 by marklgr on Friday February 10, 2017 @06:22AM (#13614626)
Most terminals support bracketed paste, and vim can automatically toggle pastemode based on the special sequences.

Eg. https://github.com/ConradIrwin/vim-bracketed-paste

Re:Vim's 25th anniversary and the release of Vim 8 by lunchladydoris on Thursday February 09, 2017 @12:25PM (#13608764)
Discovering this really changed Vim for me. That and remapping j and k to move over visual lines instead of logical lines.
Re:Vim's 25th anniversary and the release of Vim 8 by eqyiel on Thursday February 09, 2017 @03:51PM (#13610835)
What if you want to write "Dijkstra"?
Re:Vim's 25th anniversary and the release of Vim 8 by WildUtah on Thursday February 09, 2017 @04:54PM (#13611376)
That's why i use kj.

(Also: quaternions)

Re:Vim's 25th anniversary and the release of Vim 8 by farresito on Thursday February 09, 2017 @07:01PM (#13612180)
Then you wait one second after pressing j (until the timeout is over) and press k.
Re:Vim's 25th anniversary and the release of Vim 8 by chillee on Thursday February 09, 2017 @08:14PM (#13612539)
To be quite honest, that sounds terrible.
Re:Vim's 25th anniversary and the release of Vim 8 by farresito on Thursday February 09, 2017 @08:59PM (#13612713)
I don't think it's bad at all. I very rarely have to write 'jk', and using that combination saves me from having to either reach the escape key or having to use c-[. If the price I have to pay is waiting 0.5s (which is what I have the timeout configured to) once in a while, then I consider this a great tradeoff.
Re:Vim's 25th anniversary and the release of Vim 8 by minitech on Friday February 10, 2017 @01:04PM (#13617446)
Caps Lock is one key, easier to type, and even more rarely used, though. I highly recommend it. =)
Re:Vim's 25th anniversary and the release of Vim 8 by chillee on Friday February 24, 2017 @04:18AM (#13722216)
That's what I use too :). I also highly recommend it. I would strongly recommend binding either escape or ctrl to caps lock on every keyboard.
Re:Vim's 25th anniversary and the release of Vim 8 by marklgr on Friday February 10, 2017 @06:25AM (#13614638)
Or you press `<C-v>` before the `j`.
Re:Vim's 25th anniversary and the release of Vim 8 by tommorris on Thursday February 09, 2017 @04:24PM (#13611131)
Then you need to switch to Dutch mode...
Re:Vim's 25th anniversary and the release of Vim 8 by Rusky on Thursday February 09, 2017 @02:01PM (#13609771)
Personally that slows down normal usage of j too much for me.
Re:Vim's 25th anniversary and the release of Vim 8 by ngokevin on Friday February 10, 2017 @01:49AM (#13613703)
It doesn't have an effect if you type a single `j`.
Re:Vim's 25th anniversary and the release of Vim 8 by flukus on Thursday February 09, 2017 @08:02PM (#13612500)
I've been using <leader><space> lately, with space as the leader key so just <space><space> really, it's worked well so far.
Re:Vim's 25th anniversary and the release of Vim 8 by WildUtah on Thursday February 09, 2017 @04:54PM (#13611367)

    :ino kj <Esc>
    :ino <Esc> <Nop>
Try it for a week; you'll love it.
Re:Vim's 25th anniversary and the release of Vim 8 by pault on Thursday February 09, 2017 @03:17PM (#13610503)
My employer bought me a macbook with the touchbar and I've had to retrain my muscle memory to use C-[. It took a couple of weeks for it to feel natural but it wasn't nearly as bad as I expected it to be. I still haven't found a killer app for the touchbar, though.
Re:Vim's 25th anniversary and the release of Vim 8 by bartvk on Saturday February 11, 2017 @01:36AM (#13621417)
Me neither, but the TouchID is terrific.
Re:Vim's 25th anniversary and the release of Vim 8 by javitury on Thursday February 09, 2017 @01:57PM (#13609729)
For me the best way to have an accessible ESC key is just to use Alt-h, Alt-j, or just pressing Alt with any normal mode key. It will work on any vim installation out of the box, it is easily accessible and doesn't require remapping.
Re:Vim's 25th anniversary and the release of Vim 8 by groovy2shoes on Thursday February 09, 2017 @02:28PM (#13610040)
As long as your terminal is configured to send the Meta modifier as an ESC prefix rather than a shift bit, and as long as your Alt key serves as Meta.
Re:Vim's 25th anniversary and the release of Vim 8 by cassowary on Thursday February 09, 2017 @06:16PM (#13611945)
I've set my capslock to be escape and my alt to be control. I don't know where my alt is, but I've never really used it. (I think the only usecase for alt is Alt-Tab to switch windows, but that always feels epically unpredictable to me. What's going to happen? ... I prefer just clicking on the window I want).
Re:Vim's 25th anniversary and the release of Vim 8 by enthdegree on Thursday February 09, 2017 @09:24PM (#13612816)
An aside, PC XT keyboards can still be found on ebay for ~$40 and are great to use after being adapted and remapped with a microcontroller.