Hacker News new | past | comments | ask | show | jobs | submit login
Learn Vimscript the Hard Way (stevelosh.com)
195 points by stevelosh on April 4, 2013 | hide | past | favorite | 33 comments

Good stuff. And I was curious after seeing this if "Learn ... the Hard Way" was a brand that that Zed Shaw had trademarked or otherwise intended to keep exclusive. (Not that there necessarily would have been anything wrong with that, but still curious.)

But to my surprise, Shaw not only isn't proprietary about the brand, it looks like he is going out of his way to help other people appropriate it:


"This is a skeleton LaTeX project that makes it easier to start working on a “Learn X The Hard Way” book. You simply clone this repository, change a few base files, and then you can start writing. It will also come with a small “meta book” that gives you advice for writing and publishing your book."

Very cool. While it seems that Steve Losh didn't use the actual templates above (he picked markdown instead of rst), it's neat that the overall style itself is designed to be reusable.

Best of luck with the new book!

> But to my surprise, Shaw not only isn't proprietary about the brand, it looks like he is going out of his way to help other people appropriate it

I'm not sure why you were surprised, as far as I've seen Zed has generally gone out of his way to be a helpful guy. He's a bit raw and he doesn't like assholes, but he really doesn't deserve the bad rap he got in some circles. Most of it really comes from the aforementioned assholes, who happen to be more PR-savvy than him.

Uh, yeah they're not more PR savvy than I am. The vast majority of people that know about me think more like you do, and only a few mostly Rubyists think of me as some kind of boogeyman, which I also tend to cultivate since it's damn funny.

FWIW, I certainly didn't intend any disrespect (sorry that the person above jumped to that conclusion). I meant it more in the sense of a happy surprise, given that you had already freely distributed the content, also making the brand itself available was really going above and beyond.

Off topic, but almost done with Learn C the Hard Way. Great book! I was a little confused at first by pointer syntax, though. After reading K&R's C book it cleared things up for me, and then I found LCTHW great for learning more modern C practices. Thanks!

It's because earlier, unless I misremembered, someone used the name to create a work that wasn't up to Zed's standards and he told them to cut it out. He can be abrasive but he's a net win for free software. Most people angry with him are angry for immature reasons IMO.

Oh, I need to update that description. It's not LaTeX based anymore.

EDIT: Alright done. Project actually now uses reStructuredText instead of LaTeX, mostly because of issues converting LaTeX to anything other than PDF.

I would pay money for a learn golang the hard way book.

If I felt I were qualified, I would already be on it :D

Perhaps after I finish "Go, The Standard Library" as well as have a few bigger projects under my belt. By then though, someone will have probably already started on it. To be honest, I believe I heard something about someone starting on this already.

Also, Steve, would you consider using the Creative Commons Attribution-NoDerivs 3.0 license instead of a homemade license? I believe the CC BY-ND conveys most* of the same things you intended with your license, but it has the advantage of being pre-vetted by layers everywhere and the CC terms are very well understood (thus encouraging reuse in the ways you want, and ostensibly easier to enforce for the things you don't).

See: http://creativecommons.org/licenses/by-nd/3.0/

I say "most", because you also included the "so long as you do not charge anything for it" phrase in your license. Personally I'm not convinced that matters much in practice, as who is going to be able to charge for something you are giving away for free (and if they do, it'll be on a small scale, and do you really care?), and it's notoriously difficult to define things like commercial use, but if you feel strongly there's always the Non-Commercial variant: http://creativecommons.org/licenses/by-nc-nd/3.0/


Reference: http://learnvimscriptthehardway.stevelosh.com/license.html

The only time I've ever had someone complain about the "you can't make money" part of the sentence is when they're trying to run a con. Usually this involves some scheme to chop up my book and sell it on Amazon or put it up somewhere else and put ads on it. The problem with this is then the author is left with mounting support costs for all these copies sold since buyers can't tell the difference between the copies I wrote and the copies the con artist sells. They buy it then email me when they get stuck, so I'm left spending my time making somebody else money.

Anyway, I have a whole rant on how the CC licenses try to do to copyrighted art what the GPL/BSD does to software and how it just doesn't work the same.

Link to said rant? I'm interested in this, having a group of lawyers write a common legal text seems like a good thing to me, for both software and art.

I used the one I did because it's the one Zed used for his books (at least that's what it was when I started this one) and since the book is heavily influenced by his I wanted to stay in the spirit of Learn X the Hard Way.

If this were software I'd probably use a more structured license, but since it's just a book I think this is fine. Worst case: someone doesn't redistribute it because it's not a CC license. Well... they can still read it online...

I've been a vim user for something like 6/7 years now and I absolutely love it, but the editor really shows its age when you realize that its internals can only be fully customized through vimscript (i.e. you can script it using Python/Perl/Ruby but none of them offer the same interface and control that vim's own scripting language, see section 2. on http://items.sjbach.com/97/writing-a-vim-plugin), which is not exactly the best programming language around.

I wish vim would be rewritten from scratch without changing anything but the way you access and modify the guts (and possibly the "windowing" system) so that all the "fancy" plugins like Cmd-T, NerdTree, FuzzyFinder wouldn't look like crap. The maintainability of said plugins would greatly improve too if the scripting language was I don't know, Python, Ruby, Javascript/CSS and whatnot.

I must say, Sublime Text 3 with its Python 3.3 scripting is tempting. Vimscript is quite horrible.

You can script vim with Python.

Yes, but AFAIK the API isn't complete there - i.e. not all hooks are exposed as they are to Vimscript, which explains why with Python "scripting" being around for a while people still write Vimscript.

No, that's FUD. There is nothing wrong with the API exposed to Python. The main reason to write things in VimL is that this means no dependencies outside vim, which might be easier on users of your plugin. But a number of major plugins are written in Python with no problems. It's quite usable.

Which dependencies are needed to run Python plugins?

Your vim needs to be compiled with python support.

Excellent work. Have you considered making this into a Vim reference manual (:help help-writing [1])? This would make a worthy addition to the Vim distribution, imho. I always enjoyed reading through the Vim manuals (especially :help usr_41.txt [2]) on long, unplanned trips.

I'm sorry to say this, but VimL feels like an esoteric language to me. It's not a weird language per se, but it's certainly a single-purpose language (Vim's dsl) and there is something depressing in that. I don't find this to be the case with Emacs and Elisp (a lisp). Historic reasons aside, I think Lua would have made an excellent scripting language for Vim.

Disclosure: Emacs evil-mode user.

[1]: http://code.google.com/p/vim/source/browse/runtime/doc/helph...

[2]: http://vim.googlecode.com/hg-history/default/runtime/doc/usr...

This is easily the best material I've seen on Vimscript. Your example plugin for adapting Vim to a new programming language sealed the deal (especially as someone who likes to work with new languages). The book is hopefully headed to the printing press :-)

Is it OK to love Vim and hate Vim script? Because I do.

This is great, I read the book months ago on github, and have been wanting to throw some cash at you. I highly recommend it!!!

Hi Steve,

I love the work you have made with this. I use it as a reference each time I have to make something new.

Also, I like your idea of two-spacing. :)

I'm gonna try this along with 'Practical Vim'. Thanks.

Title is a bit redundant. Vimscript is the most stupidly hard (as in, cryptic syntax and semantics for no good reason) language this side of Brainfuck.

Not really true. Half of it is just using vim commands within the language (such as set and normal), and it does get a bit weird with execute and all the string escaping. Vim regex is quite non-standard but that's because the use case in the editor makes for very different escaping rules than in programming, so basically just use very magic more (\v) in code.

The other half is a pretty standard syntax, with exception to needing 'call function()', which feels like some old language with a strict statement structure. But the semantics are actually quite similar to JavaScript, dictionaries especially are very straightforward.

To me the worst part of Vimscript is that it allows every word and command to be reduced to the minimum unambiguous set of characters, which is understandable in one-offs in an editing context. But some developers take it a bit far doing big codebases with those horribly shortened keywords, as much as it can be done. It just detracts from the community (people who would like to read code are put off) and quality of open source output.

Not being a Pythonista or Rubyist myself (but a PHP/JavaScripter) I found Vimscript quite easy to get into.

Those things we always hear about Vimscript sucking are mostly cargo culting by people with no experience with Vimscript in the first place. I personally hate the syntax of Ruby or Objective-C but I don't go around mocking those languages.

Anyway, your comment on shortening commands is very true. Case in point, the great CtrlP plugin:


It's an awful read but, once you replace all the shorthands with full names, the code is very readable and straightforward. To me, it looks pretty much like a PHP/JS without braces.

CtrlP was exactly my mental case in point when I commented on that. I needed to add some stuff to it, which I did begrudgingly after seeing the source, but now I'm considering forking it and rewriting in Lua both for speed (it's slow) and for readability. And as a pet project in Lua, of course.

I hear you. Good luck finding users with Vim compiled with lua support, though.

I've been working on a language [1] that compiles (transpiles?) into Vimscript. Makes most things easier, I find.

[1] https://github.com/luke-gru/riml

That looks really cool!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact