Building your own Sublime out of free components with vim

I recently wrote about Sublime Text, and what a nice text editor it is. It really is a very nice editor and I don’t want to rain on its parade. I bought a license even though I never use proprietary software for work, haven’t used any for over 10 years now. That’s how good I think Sublime is.

But if you’re comfortable with an editor like vim, you can make vim feel almost like Sublime, using only free and open source software (FOSS). vim (and emacs) have had many of the features that Sublime has, in some cases for decades. Here’s a very small and simple guide for making vim look and behave a little like Sublime.

First, install the required components into your .vim directory:

  1. vundle instead of pathogen to manage plugins automatically.
  2. NERDtree gives you a separate directory tree to browse and open files from, like the left-hand side tree in Sublime.
  3. A terribly nice 256 color color scheme (works in the terminal and in the vim GUI version): xoria256. Make sure your terminal supports 256 colors, set your TERM variable to something like xterm-256color. If you use a terminal multiplexer like screen or tmux, set it to screen-256color to make sure your background colors work properly.
  4. To replicate the Control-P/Command-P (Go To File) behavior found in Sublime, you can use vim’s Command-T plugin. Thanks for the hint, Stefan! Another similar plugin, written entirely in vimscript so it doesn’t need Ruby, is ctrlp.vim.
  5. Set up your vimrc to load most of this stuff. See below for mine.

Example .vimrc:

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
 
Plugin 'gmarik/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'
 
call vundle#end()
 
syntax on
filetype plugin indent on
:set number
colorscheme xoria256

Restart vim and do a :PluginInstall.

After another restart of vim you can execute :NERDtree to get a nice tree on the left-hand side, then open a file and perhaps split your window (Ctrl-W n) and load each of the files in separate split frames. Navigate back and forth between frames using Ctrl-w Ctrl-w (or Ctrl-w followed by the arrow key of the direction you want to move in). You can also split each of the frames into tabs, just like in Sublime.

And to finish off, one of the features I use most frequently in Sublime is the “find inside files in a folder” search (Ctrl-Shift-F). In vim, you can accomplish the same using e.g. vimgrep. First, grep for something in the files you want: :vimgrep meta_datum **/*.rb. Then bring up the quicklist to see your results: :cw. This way, you can navigate almost in the same way as in Sublime.

Two screenshots of all this combined below. Now go on and customize vim to fit your needs exactly!

9 thoughts on “Building your own Sublime out of free components with vim”

    1. That’s pretty awesome! But you it would really, really benefit from GNU/Linux and Windows support. Otherwise it’s “just” a MacVim plugin, not a vim plugin 😦

      Could it run in the plain-jane console vim as well? The plugins I’ve referred to above all run even in console mode, so if I like, I can have all that stuff over SSH when tinkering around on my web server.

      Like

      1. Yes. But shortcuts on mac are only usable with MacVim. I’ll implement Linux support too in the future (like using only ctrl mappings instead of cmd).

        Like

    1. You’re right, I should mention Atom. I wrote this article over 3 years ago, when Atom didn’t exist 🙂 Though Sublime clearly inspired Atom as well, so most of the stuff applies.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s