Skip to content

Instantly share code, notes, and snippets.

@ianchanning
Last active April 23, 2017 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianchanning/673dd39b9729f196ca83291901ccbad6 to your computer and use it in GitHub Desktop.
Save ianchanning/673dd39b9729f196ca83291901ccbad6 to your computer and use it in GitHub Desktop.
Translating Sublime Text into Vim

Translating Sublime Text into Vim

Intro

Coming from a Windows world getting into Vim, to me is almost exactly like the struggles I had learning French or Dutch. I spent 10 years learning French growing up and I can't speak a proper sentence. I then moved from England to the Dutch speaking part of Belgium (Flanders) and I learnt to speak Dutch to a conversational level within 2 years.

If you're going to learn Vim you need to immerse yourself in it. I suspect the majority of Vim users only ever use it to make minor file modifications via SSH. That's what I did anyway.

I've used lots of editors in Windows but the one I prefer now is Sublime Text (ST). However ST has almost all the exact same commands as other editors, with the one major improvement which is Ctrl+P, we'll come to that later. ST is free to use with a popup once in a while, its a great tool, you should buy a licence.

So for users of all other editors, all you have to do is learn the elements of Sublime Text I use here and then you should be able to translate them to your own editor. I hear you notepad lovers. So we'll use ST as the boundary layer between our nice fuzzy Ctrl + N, Ctrl + C, Ctrl + V and :e, y and P.

Why O Why

Is it worth the pain?

I mean, the question 'How to close Vim?' has a 1000+ up votes on Stack Overflow. That's insanity.

However, I think that if you master Vim the layer between your thought and your code becomes thinner. So this has nothing to do with linting or plugins this has to do with performing at a higher level with the code that you write.

Also I think Vim is just misunderstood. This is where my analogy of learning a spoken language comes from. Switching between Windows editors is like switching dialects sure some of the Scottish folk sound funny, but you can understand what they say. All of us assume that Vim is just another dialect, but it's not. It's like nothing you've used before. So there's nothing for your brain to grab on to and understand.

  1. Vim gets you closer to your code. Once performant in Vim you can perform code editing tasks faster and keep up with the speed of your thought. This breaks through the ceiling that you will hit with most other GUI editors.
  2. Vim is very fast, I don't think it's necessarily faster than ST, but certainly it's at that level, everything happens instantly. There's none of the delay that you sometimes have with opening ST or other heavier editors e.g. Netbeans, IntelliJ. Speed is one of the barriers between your thought and your code, slow editors are slowing you down.
  3. Vim is cross-platform and works via the command line, every benefit you learn on Windows means that you have the multiplied benefit that you can use the exact same instructions on Linux or on Mac. Again so it ST, but Vim works via SSH, it works in Docker it works everywhere.
  4. Once you learn the commands you can do things quicker, deleting a word is just typing dw, once fluent this can be performed faster than using the mouse or Ctrl+Shift+Right-arrow, Delete. These are small 1% improvements, but they add up.
  5. Vim has a command history. This is really useful for doing repeated things. Sure your search box in other editors has it plus you'll have recent files that you've opened, but every single command that you type is recorded. My example for this is reformatting code with Regex. Once you've closed your regular editor your search and replace history is lost. In Vim it's there waiting for you.
  6. Not only that but anything you did as the last command can be repeated with .. This can be complex things like repeating all the text you just typed in Insert mode. Or if you just cut a line and you want to paste it a few times, now you're just typing . instead of Ctrl + V.
  7. Syntax highlighting! In the DOS prompt, SSH prompt! Seriously, this is amazing. Windows has been around for 30 years and there's nothing else I know of that can give you this.
  8. Less Chrome. Vim is mostly like using the distration free mode of Sublime Text all the time. Less distraction, more thinking.
  9. Everything you've got in your editor currently: Tabs, Split screen, Projects, Linting, REPL, Plugins, Sidebar file tree. But we're still in the donkey DOS prompt here.
  10. Closer to the command line. Again thinning that barrier between you and your code. In Vim you can type ! and then any command line command, e.g. !mkdir temp or !python will allow you to drop into the python REPL and then come straight back to Vim once you're done.

Lesson 1: Install Vim

I'm going to focus on using Vim inside the DOS prompt. I think it is the simplest purest way of using Vim in Windows. Hopefully it also means I can help more people, Powershell users can probably translate the DOS commands more easily to Powershell than vice-versa. Linux and Mac users used to using GUI tools should be able to figure it out too. When I write Ctrl + C people will understand, when I write <C-c> users unfamiliar with Vim / Emacs will stare blankly.

Vim comes with Git for Windows. Install this via Chocolatey. If you don't use chocolatey on Windows your developer's life is poorer for it. We then need to add the GNU usr tools to our PATH.

> choco install -y git
> PATH %PATH%;C:\Program Files\Git\usr\bin

This only adds the PATH for the current session. Update your PATH environment variable to do it permanently.

This gives you all the loveliness of all the GNU tools e.g., ls, grep as well. If you really want to do yourself a favour install clink and solarized DOS prompt colours too.

Lesson 2: Basic commands

You can skip this if you know the commands. I knew the basics of these for years before I started immersing myself in the rest of Vim.

The weirdest concept I had (after years of very light usage) is typing :w instead of :x to write the file, because now we actually want to stay in Vim, rather than get the hell out as fast as possible.

Command Sublime Text Vim
Undo Ctrl+z u
Redo Ctrl+y Ctrl+r
-
First line Ctrl+Home gg
Last line Ctrl+End G
Line N Ctrl+g, N, Enter Ngg
End of the line End End / $
Start of the line Home Home / 0
Next word Ctrl+Right w
Previous word Ctrl+Left b
Page up Pg Up Ctrl+u
Page down Pg Dn Ctrl+d
Find Ctrl+f, [text], Enter (forward) /[regex] (forward) / ?[regex] (back)
Replace Ctrl+h, [search], [replace], Enter (forward) :s/[search]/[replace]/, Enter / :%s/[search]/[replace]/, Enter (global)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment