Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 565bb80fceffe53baa038f0c

No naked if allowed!

House style forbids naked condition statements, comments should start with a space character and be on their own line. Good luck!

Start file
#include <sock.h>
if (recvfrom(s, (char*)&ms, sizeof(ms), 0, foo, bar) >= 0) //receive initial message frame
{
	f++;
	if (f == snwseq) //if its the right sequence
	{
		if (sendto(s, (char*)&a, sizeof(a), 0, foo, bar) > 0) //Send ACK
			log << "Send ACK " << snwseq << ".\n";
		else
			cout << "Error!" << endl;
	}
	else //wrong sequence
	{
		receive_packet_transfer(s, a, sa, f, slen, snwseq, num); //wait for correct packet
	}
}
else
	cout << "Error!" << endl;
End file
#include <sock.h>
if (recvfrom(s, (char*)&ms, sizeof(ms), 0, foo, bar) >= 0) {
	// receive initial message frame
	f++;
	if (f == snwseq) {
		// if its the right sequence
		if (sendto(s, (char*)&a, sizeof(a), 0, foo, bar) > 0) {
			// Send ACK
			log << "Send ACK " << snwseq << ".\n";
		} else {
			cout << "Error!" << endl;
		}
	} else {
		// wrong sequence
		receive_packet_transfer(s, a, sa, f, slen, snwseq, num);
	}
} else {
	cout << "Error!" << endl;
}

View Diff

2,3c2,3
< if (recvfrom(s, (char*)&ms, sizeof(ms), 0, foo, bar) >= 0) //receive initial message frame
< {
---
> if (recvfrom(s, (char*)&ms, sizeof(ms), 0, foo, bar) >= 0) {
> 	// receive initial message frame
5,7c5,8
< 	if (f == snwseq) //if its the right sequence
< 	{
< 		if (sendto(s, (char*)&a, sizeof(a), 0, foo, bar) > 0) //Send ACK
---
> 	if (f == snwseq) {
> 		// if its the right sequence
> 		if (sendto(s, (char*)&a, sizeof(a), 0, foo, bar) > 0) {
> 			// Send ACK
9c10
< 		else
---
> 		} else {
10a12,15
> 		}
> 	} else {
> 		// wrong sequence
> 		receive_packet_transfer(s, a, sa, f, slen, snwseq, num);
12,17c17
< 	else //wrong sequence
< 	{
< 		receive_packet_transfer(s, a, sa, f, slen, snwseq, num); //wait for correct packet
< 	}
< }
< else
---
> } else {
18a19
> }

Solutions

The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!

Check out these helpful resources to improve your Vim skills... Game on.

Unlock 16 remaining solutions by signing in and submitting your own entry
#17 glepha / @glepha_vim - Score: 81 - 03/06/16 @ 23:59
jf/qad$Jo<Esc>p==lli <Esc>qjjf/@ajf/d$A{<Esc>o<Esc>p==lli <Esc>jo}<Esc>JA {<Esc>jo}<Esc>jJf/@ajf/hd$jjJA {<Esc>jo}<Esc>ZZ

0 comments


Created by: @samasuy

17 active golfers, 39 entries

Leaderboard (lowest score wins):
46
#1 - Urtica dioica / @udioica

11/30/2015 at 04:17AM

46
#2 - Petro Тrouq / @zulolosi

02/03/2016 at 07:32PM

46
#3 - vimgolfer / @vimgolfer7

10/05/2019 at 01:55PM

46
#4 - John Braxler / @braxler

10/18/2019 at 07:53PM

46
#5 - Peppa Pig / @PeppaPigSg

07/03/2024 at 01:28AM

55
#6 - Filipe Brandenburger / @filbranden

07/08/2019 at 11:46PM

56
#7 - Carlos A Henríquez Q / @lagunex

03/26/2016 at 02:16PM

57
#8 - Stanislav / @prstad

09/14/2016 at 12:30PM

58
#9 - Eric Banisadr / @ebanisadr

02/03/2021 at 12:05AM

58
#10 - constap / @constap

05/07/2024 at 08:24PM

58
#11 - nickGPT / @nickandbro

08/28/2024 at 03:45AM

71
#12 - Saki Gw / @Sakigw

05/22/2016 at 05:02PM

71
#13 - vimgolfer24271 / @vimgolfer24271

05/13/2019 at 01:42PM

73
#14 - isaneba / @isaneba

07/26/2016 at 03:01AM

79
#15 - 杨洋 / @176795444

07/04/2017 at 04:13AM

80
#16 - Tomek Borek / @LAFK_pl

08/24/2016 at 05:23PM

81
#17 - glepha / @glepha_vim

03/06/2016 at 11:59PM