News for hackers. Stuff that matters.
Re:Vim's 400 line function to wait for keyboard input by Alupis on Wednesday July 15, 2015 @03:39PM (#9893581)
> The code works, but it's quite buggy

Could you elaborate a bit? I've never experienced a bug related to keyboard input while using Vim, at least that I know of.

Re:Vim's 400 line function to wait for keyboard input by solutionyogi on Wednesday July 15, 2015 @03:55PM (#9893683)
He covers in the blog post: http://geoff.greer.fm/2015/01/15/why-neovim-is-better-than-v...

From the blog post:

That if statement’s conditions span 17 lines and 4 different #ifdefs. All to call gettimeofday(). Amusingly, even the body of that statement has a bug: times returned by gettimeofday() are not guaranteed to increase. User intervention or ntpd can cause the system clock to go back in time. The correct solution is to use a monotonically increasing time function, such Linux’s clock_gettime() or OS X’s mach_absolute_time().

Re:Vim's 400 line function to wait for keyboard input by harmil on Wednesday July 15, 2015 @04:39PM (#9893940)
ntpd guarantees (under the default settings now, though that's new... you can ask it to shoot you in the head, but I don't recommend that you use firearms in this way) that the clock will never go backwards. You're thinking of nptdate, a utility provided with ntpd, but which is only ever supposed to run at system initialization time to get the time close enough for ntpd to take over.

If ntpd finds that the clock is ahead, it will slow the ticks, allowing it to gradually drift back to the correct time.

The system time should NEVER move backwards. Ever. Relying on the system time not moving backwards is not unreasonable for trivialities like how long you wait for a keystroke. If you reset your system time, you might have to hit a key to get vim to wake up. Shucks.

Re:Vim's 400 line function to wait for keyboard input by dlubarov on Wednesday July 15, 2015 @07:19PM (#9894622)
ntpd will step backward if error stays above a configurable threshold for a configurable period of time. We saw it happen after the recent leap second. 1 second exceeds the default step threshold of 128 ms. With Linux limiting the slew rate to 500 ppm, gradual correction would have taken 2000 seconds, and by default nptd steps after 900 seconds.

> ntpd guarantees (under the default settings now [...]) that the clock will never go backwards.

Can you elaborate on what changed? I just downloaded the latest reference implementation, and the man page still seems to indicate that the default behavior is to step when error > 128ms for a prolonged period.

Re:Vim's 400 line function to wait for keyboard input by jschwartzi on Wednesday July 15, 2015 @10:43PM (#9895252)
There is no such guarantee when using CLOCK_REALTIME. If you need this guarantee, use the monotonic clock. I've had issues with graphics engines written naively assuming nobody would change CLOCK_REALTIME. It's a bad assumption because many embedded systems well not use ntp and will instead rely on a user to set the clock. It may go backwards if the user sets it backwards. It may even do so while your software is doing something like presenting the user with a UI to set the time.
Re:Vim's 400 line function to wait for keyboard input by zyztem on Wednesday July 15, 2015 @05:16PM (#9894132)
With Linux/NTP there was two times 23:59:59 UTC not long ago: https://access.redhat.com/articles/15145
Re:Vim's 400 line function to wait for keyboard input by biggestbob on Wednesday July 15, 2015 @07:30PM (#9894672)
The clocks go back an hour every year here in (most of) Australia. Every year, on a specific date 1am-2am happens twice.
Re:Vim's 400 line function to wait for keyboard input by hkmix on Wednesday July 15, 2015 @07:38PM (#9894705)
Do you mean daylight saving time? The time zone changes, but Unix time is UTC so it's unaffected.
Re:Vim's 400 line function to wait for keyboard input by sigzero on Wednesday July 15, 2015 @05:04PM (#9894071)
> he correct solution is to use a monotonically increasing time function, such Linux’s clock_gettime() or OS X’s mach_absolute_time().

At the expense of supporting FEWER platforms.

Re:Vim's 400 line function to wait for keyboard input by roghummal on Thursday July 16, 2015 @12:29AM (#9895487)
Another #ifdef would fix that!

A wrapper function could hide the extra #ifdef, taking it out of OP's count. A macro defined during compilation would be even better|harder to understand.

Re:Vim's 400 line function to wait for keyboard input by cpncrunch on Wednesday July 15, 2015 @03:52PM (#9893658)
Me neither. I've been using vim for about 20 years and I don't think I've ever spotted a single bug in that time.
Re:Vim's 400 line function to wait for keyboard input by vacri on Wednesday July 15, 2015 @08:06PM (#9894853)
I don't know whether it's technically a bug or not, but vim is often a bit slow. For example, 'o' to open a new line in insert mode sometimes takes up to two or three seconds to work. Not a huge problem, but enough to make my mental flow stumble. I have a small vimrc that's mostly tab-related stuff, so I don't think it's that.
Re:Vim's 400 line function to wait for keyboard input by simoncion on Thursday July 16, 2015 @02:38AM (#9895739)
I've also noticed delays when using 'o'. I've always wondered if it might be related to syntax highlighting.
Re:Vim's 400 line function to wait for keyboard input by winternewt on Wednesday July 15, 2015 @04:28PM (#9893852)
vim crashes or hangs for me about once every month. I've never bothered to find out why since I don't think it's worth the effort. The effort would be lower if the code was cleaner and didn't have so much bloat related to platforms that don't exist. It would definitely be easier to submit a patch if I didn't need to cater to all the platforms I've never seen.
Re:Vim's 400 line function to wait for keyboard input by jrbrtsn on Wednesday July 15, 2015 @05:52PM (#9894309)
Most likely you've typed Ctrl-S, which causes the terminal to pause. Here is the what the vim docs have to say about that:

Note: CTRL-S does not work on all terminals and might block further input, use CTRL-Q to get going again.

Re:Vim's 400 line function to wait for keyboard input by MereInterest on Wednesday July 15, 2015 @07:24PM (#9894653)
If you run "stty -ixon", it will prevent Ctrl-S from pausing the terminal. I understand that feature in the days of slow connections, but it feels rather silly at this point.
Re:Vim's 400 line function to wait for keyboard input by nitrogen on Wednesday July 15, 2015 @07:40PM (#9894719)
I use it to pause output from a running batch job (e.g. deployment).
Re:Vim's 400 line function to wait for keyboard input by joeheyming on Wednesday July 15, 2015 @06:27PM (#9894444)
This was my biggest hurdle to learning vim, I kept hitting Ctrl-S...
Re:Vim's 400 line function to wait for keyboard input by firebones on Wednesday July 15, 2015 @09:53PM (#9895124)
This might help:

http://vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_...

(Caveat emptor, can't speak from first hand experience.)

Re:Vim's 400 line function to wait for keyboard input by PhasmaFelis on Wednesday July 15, 2015 @07:52PM (#9894778)
That is fascinating to me, in a train-wreck sort of way.

We had a discussion a few days ago about the ways in which some interfaces (command line in particular) can be user-hostile. (https://news.ycombinator.com/item?id=9831429) Vim's Ctrl-S appears to be a function, keyboard-adjacent to several commonly-used functions, whose main effect for many users is "cause the program to fail immediately with no indication of how to fix it." I don't think I could make up a better example of user-hostile design if I tried.

Re:Vim's 400 line function to wait for keyboard input by 6502nerdface on Wednesday July 15, 2015 @09:00PM (#9895006)
It is not "Vim's Ctrl-S"; it's the terminal emulator's ctrl-s. Same thing happens in less, for example.
Re:Vim's 400 line function to wait for keyboard input by PhasmaFelis on Thursday July 16, 2015 @05:54PM (#9900112)
Ah, my mistake. Same criticism applies, though; possibly more so, as a terminal emulator running within a GUI would find it even easier to display a useful status message or similar.
Re:Vim's 400 line function to wait for keyboard input by omaranto on Wednesday July 15, 2015 @06:07PM (#9894362)
I've never heard of Ctrl-S causing a crash, though. So your explanation at most accounts for the hangs.
Re:Vim's 400 line function to wait for keyboard input by jrbrtsn on Thursday July 16, 2015 @08:18AM (#9896706)
I've used vim pretty much every work day in the last 15 years or so, and I can count the number of times it's crashed on one hand. If you can actually verify that it crashed (i.e. core dump file), then you've got the source available, and you can send in the patch.
Re:Vim's 400 line function to wait for keyboard input by omaranto on Thursday July 16, 2015 @01:37PM (#9898637)
It's never crashed on me. I'm not the person who claimed it crashed.
Re:Vim's 400 line function to wait for keyboard input by Watabou on Wednesday July 15, 2015 @04:45PM (#9893973)
Are you sure the crashes aren't caused by a plugin you installed?

I have only experienced a handful of vim crashes but all of them were caused by plugins.

Re:Vim's 400 line function to wait for keyboard input by mintplant on Wednesday July 15, 2015 @05:37PM (#9894239)
vim may still be partly to blame in that case, as it lacks support for async plugins.
Re:Vim's 400 line function to wait for keyboard input by Watabou on Thursday July 16, 2015 @12:00AM (#9895433)
Do you also blame Microsoft Word because it doesn't let you play movies?
Re:Vim's 400 line function to wait for keyboard input by mintplant on Thursday July 16, 2015 @02:51AM (#9895757)
People have tried to add async plugin support to vim, but the patches have all been rejected. Meanwhile, the plugin support in Neovim is worlds better.

Microsoft Word doesn't even accept patches, which I do indeed hold against it.

Re:Vim's 400 line function to wait for keyboard input by Watabou on Thursday July 16, 2015 @02:27PM (#9899029)
The patches were rejected because they didn't provide a working solution for cross platform support. The plugin system in Neovim is only "better" for people who actually want async plugins. I am not one of them.
Re:Vim's 400 line function to wait for keyboard input by nothrabannosir on Wednesday July 15, 2015 @04:47PM (#9893987)
When I press ESC, it takes a while to register, and for the UI (e.g. the little "command in progress" buffer bottom right) to reflect this. CTRL+C doesn't suffer this problem, and is almost functionally interchangeable, so I've retrained myself to use that, now.

This is a bug, if you ask me. Or is that impossible for vim to fix?

Re:Vim's 400 line function to wait for keyboard input by nanofortnight on Wednesday July 15, 2015 @05:04PM (#9894073)
This is not a bug in vim. This is because Esc was historically used as a Meta key in lieu of the modern use of Alt.

For example, if you use tmux, add the following to .tmux.conf:

    set -s escape-time 0
Other terminal multiplexors and emulators have different commands for this.

Edit: There are a few other possible issues you are having: http://www.johnhawthorn.com/2012/09/vi-escape-delays/

Re:Vim's 400 line function to wait for keyboard input by hkmix on Wednesday July 15, 2015 @07:40PM (#9894718)
In vim, set separate timeout and ttimeout values to get around this. Specifically, set the former high fit regular commands and the latter low to avoid issues like slow Esc processing.
Re:Vim's 400 line function to wait for keyboard input by baby on Wednesday July 15, 2015 @03:51PM (#9893653)
Depends on what machine you are using Vim from