2015-04-13

from sublime to vim

So I've decided to try learning vim one more time.

I did one unit in uni on vi, but the lecturer was so monotone and repetitive that the only thing I learned was.
Press esc to exit command mode, to exit command mode press esc. The command mode can be exited by pressing the esc key.

At my first job a few people used vim, but when I asked why they didn't use a modern IDE, they just shrugged and said, "I'm used to it and it's efficient"

The unique concept in vi that no one ever mentioned (or I just didn't understand) was composable commands, especially when combined with modes:

https://medium.com/@mkozlows/why-atom-cant-replace-vim-433852f4b4d1

http://ferd.ca/vim-and-composability.html

Whenever I used vi, the normal/insert/command modes felt like a burden, because I was always in insert mode, and ctrl-s is much easier than esc :w

I learned a couple of normal mode things like :wq :q! r x i d dd dd y p / and regex search and replace, but that's a really awkward way to edit text. I thought of them as unrelated and obscure commands, when really they are verbs. I never bothered to learn about the nouns; text-objects and movements, let alone adjectives.

I used eclipse as and IDE, and actually spent time learning the shortcuts, so I was much more effective with that. ctrl to move over words, shift to select, ctrl+alt to move selected blocks etc.
Almost every editor/IDE I've used since have a similar set of actions with the same keys, and most OSs have them built into every text box, (even blogger).

I used emacs for a few years, after a colleague showed me some of the power and extensibility, compared to IntelliJ IDEA. I was writing macros, had my own custom key-bindings that worked properly with my dvorak keyboard, and I was processing text faster than ever.

I then started working on both an iphone app and a .net web app. both of which required the use of xcode and visual studio respectively.
I stopped using emacs every day, as 3 editors/IDEs was too many to be using every day.

After that I started looking into rails again, and everyone was using sublime text 2. So I thought I'd give that a go.
It seemed to have the power of emacs, with the navigation/editing keys of everything else.

ctrl-P and multiple cursors just blew my mind. (which I hadn't seen before)

I've been using sublime 2/3 for a few years now, and was getting annoyed a little things all the time, but nothing bad enough to look for alternatives.

Then I read this:
https://advancedweb.hu/2015/03/31/why-you-should-care-about-vim/

I finally grokked vim.

If you're always in normal mode, it's easier to diw than it is to ctrl-left ctrl-shift-right del
Being in the normal mode means you don't need all the modifier keys.

Now, it seems weird that I can only enter "normal mode" in other editors by holding down ctrl!

Because it's a language (diw=delete inside word), it ends up being easier to remember than the sequence of ctrl commands.

And if you learn a new modifier y (yank/copy), or a new text-object like p (paragraph), you're extending the knowledge you already have, rather than remember a new combination, or just repeating and existing key.
eg
yip or up, up, up, up, shift+ctrl+up, ctrl+c
yis or ctrl+[left, left], shift+ctrl+ [right, right], ctrl+c

I'm no longer holding down 2,3 (4 on the laptop of end) keys at once to copy a section of text, I just type three letters.

It does help my hand and wrist pain, and it's less keys; sure.
But the more important thing is that I can think about my edits at a higher level of abstraction.
Instead of just characters, lines and pages, I can think about characters, words, WORDS, sentences, blocks, paragraphs, indented sections, tags; All the things that I actually think about when I'm working on code.
eg
delete this html tag = dat
copy the body of a coffeescript function = yii

Just like any programming language, you have methods of combination and methods of abstraction.

http://www.billthelizard.com/2009/10/sicp-notes-from-lecture-1a_04.html

Lots of editors have methods of abstraction: plugins and macros,
and simple methods of combination: ctrl+shift+alt with arrow/home/end/pageup/pagedown keys

but nothing compares to vims verb/adjective/noun form of combining search, editing or movement, with all types of things on the screen.

It's got me thinking about what other kinds of nouns I could add with a plugin.
But I really need to learn the basics before I start learning vimscript.

If you're used to an IDE, vim is something that really needs to be set-up before you start,
as the defaults are based on compatibility rather than state of the art.

This is a great way to learn the basic concepts, and set up a basic config
http://inside.github.io/vim-presentation/#/


I've really only just started learning vim (properly this time)
so where's some links to resources that I've found helpful at this early stage.

This was awesome fun, but US$25 is a bit much for only 6 months
http://vim-adventures.com/

This is almost as fun, and I'm actually learning a lot very quickly US$5 for just vim is a decent price
https://www.shortcutfoo.com/app/dojos/vim

Here's a cheat sheet that's actually compact enough to be useful
http://sheet.shiar.nl/vi

http://stevelosh.com/blog/2010/09/coming-home-to-vim/
http://benmccormick.org/learning-vim-in-2014/

Here's some ways to help vim feel more IDE like, a softer way to make the transition
http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
http://yannesposito.com/Scratch/en/blog/Vim-as-IDE/

Some issues that I haven't noticed yet
http://andre.arko.net/2013/09/11/vim-is-the-worst-editor/

I'm liking this color scheme at the moment, twilight:
http://www.vim.org/scripts/script.php?script_id=1677

in file search:
https://github.com/ggreer/the_silver_searcher

coffeescript
https://github.com/majutsushi/tagbar/wiki#coffeescript

No comments:

Post a Comment