Vim 101: Practicing Marks

Recently I've had several experienced Vim users tell me that they don't use marks. Mastering marks is just a question of practice, and the easiest way to get the hang of them is by using two commands:

  • :marks: This will list all of the current marks
  • '': Move to the position before the latest jump

Looking at :marks periodically will help you visualise how marks work. The '' command will potentially improve your workflow: it causes the cursor to move to the position before the previous jump.

Jumps are actually a class of motions. Motions are commands that move the cursor. When you move the cursor, Vim stores the previous position, and the previous position can be accessed with ''.

Read More →

Vim as an Xcode Alternative

As I've mentioned before, I do freelance work as an iOS developer. This is, of course, awkward and painful as a Vim user because it can be a challenge to work productively outside of Apple's IDE. I like to keep tabs on resources for working with Vim and iOS/Mac development, so here's one of my latest finds: a detailed post by Benedikt Terhechte about using Vim as an Xcode alternative. The author explains how to install Clang Complete, and some additional libraries like surround.vim and ios.vim.

The Carbon Five blog also has lots of resources for working with Xcode outside of the GUI. Building Xcode 4 projects from the command line has some help for dealing with xcodebuild, although if I remember correctly I last got automated builds working by following this answer on Stack Overflow.

Read More →

Script Roundup: movar, vim-fat-finger

Send in your Vim scripts for review through our contact form or @vimnews.


Inspired by the Vim London meetup, Rob Miller wrote movar (GitHub: robmiller / vim-movar) which adds some motions for moving around variables in PHP and Ruby. He's used the onoremap command with a function that builds up a string that searches using searchpos.

Typing av will select around a variable, while iv selects inner variables (thereby ignoring the variable's prefix, like $). These motions work with operators as well, so you can delete, change, or yank.


vim-fat-finger (GitHub: chip / vim-fat-finger, fat-finger) by Chip Castle supports over 4,000 commonly typed misspellings, which are corrected using the iabbrev command. It doesn't have any settings, but the author has mentioned a toggle feature in the project's TODO file.

Read More →

Vim 101: Fancy Tags

Two weeks ago I wrote a Vim 101 on tags, which introduced the basics for working with Vim's tag navigation tools. Something that I hinted at was using tags to help visualise a project's structure. Although Vim's raw editing operations are incredibly powerful, some of us need help in trying to visualise the structure of a project, and to navigate around it. I often find it takes a few hours or even days to get to grips with an already established code base.

There are several popular plugins designed to help visualise code through the use of tags. One such project, Tagbar (GitHub: majutsushi / tagbar, License: Vim, Tagbar) by Jan Larres displays a tag browser at the side of the screen. It automatically generates tags for the current file, and shows a menu of functions and methods, classes, and even things like macros if you're working with C.

I usually find I'll break out Tagbar when I'm trying to figure out the overall structure of files within a new project. Then once I've got a feel for it I'll switch back to a combination of tag navigation and searching.

Read More →

Vim, Instinct, and Muscle Memory

Ryu mastered motions and operators before mastering Hadoken

One thing that came out of my talk on Custom Motions at Vim London was the idea of instinctively hitting the escape key to leave a mode. I first started to think about this when I came back to my computer and the screen had slept. I hit a key in order to wake the screen, and then I was presented with a Vim session. Since I didn't know exactly what key I'd hit, I pressed escape because I knew that would put Vim back into a familiar state.

If you also find yourself doing that, it's probably because at one time or another you've accidentally entered into Operator-pending mode. Vim has no visual indication when this mode is active -- it's like a sub-mode of Normal mode.

Read More →

Script Roundup: Vimpanel, Seek

Send in your Vim scripts for review through our contact form.


Vimpanel (GitHub: mihaifm / vimpanel) by "mihaifm" is a new tree explorer, influenced by NERD Tree. Panels can be created based around projects, and can be comprised of different folders and files as required. Sessions are supported, so the state of panels and windows can be reloaded after exiting Vim.

Vimpanel is more like the project navigation panels found in GUI text editors like Sublime Text or TextMate, rather than being purely oriented around file system navigation.


Seek (GitHub: goldfeld / vim-seek, License: Vim) by Vic Goldfeld shows we still haven't mined the depths of the flexibility provided by the concept of motions. It provides a new motion, s, which works like f. Where f takes a single character as an argument to jump to the next occurrence, Seek takes two characters, thereby reducing the number of potential matches.

Read More →

Vim 101: Preview Window

Continuing on from last week's Vim 101 on tags, another useful element to a tag-based workflow is the preview window (:help preview-window). There's only ever one preview window per tab page, and it can be used to display tag definitions without interruption.

Typing :ptag tagname will open the preview window for "tagname". If you follow through last week's tutorial using Vim's source, you could type :ptag curbuf to see the definition of EXTERN buf_T in src/globals.h. When the window opens, it won't steal focus, which makes it essential for quickly looking up function signatures without wrecking your concentration when you need to navigate back.

If you type :ptag again, Vim will display "tag 1 of 2 or more" (this will be automatically displayed when there's no other message). Typing :ptnext or :ptprevious allows you to navigate between the matching tags.

Read More →

The New Powerline

Powerline has been rewritten in Python. The old Vim script version is still available at Lokaltog / vim-powerline. There was a discussion last year, Port core code to Python, where Lokaltog (Kim Silkebækken) discussed the merits of porting the core of Powerline to Python. As a result, the same statusline effect can be applied elsewhere: Zsh, Bash, and tmux are all supported.

The only slight wrinkle in this new version, however, is Python on Macs. The Powerline installation instructions have the innocuous line: pip install git+git:// Let's just say if you're using a Mac, you may be in for a bit of extra work. It's possible your Vim has been built with a different Python than the one pip uses. You might have even installed Python with Homebrew, and you could have even installed Vim Homebrew as well. Either way: your particular environment might not work out of the box.

If you do have problems running the new Powerline, this comment in the GitHub repository explores it in some detail: Mac OSX 10.8.2 (Fails to load properly). The thing to do is type :python import sys; print(sys.path) from within Vim to determine which site-packages folder should be used to install the Powerline Python module.

Read More →

Script Roundup: togglecursor, jk-jumps

Send in your Vim scripts for review through our contact form or @vimnews.


togglecursor (GitHub: jszakmeister / vim-togglecursor, License: Vim) by John Szakmeister will change the cursor to a caret-style graphic when entering insert mode in iTerm and Konsole. I tested it in iTerm2 and it works. I'm not sure how I feel about it though, it makes the cursor harder to see on my screen which is probably a bad idea.

The script itself takes into account tmux, and I confirmed it works with Vim in tmux as well.


jk-jumps (GitHub: teranex / jk-jumps.vim, License: Vim) by Jeroen Budts makes j and k add entries into the jumplist, so they behave more like jump motions (:help jump-motions). If I'm reading the source correctly, it remaps j and k to work using the G command, which modifies the jumplist.

Read More →

Vim 101: Tags

A big part of editing that often gets overlooked is file navigation. Effective file navigation is a skill that can help improve productivity, but also aids visualisation of a project.

Vim's bare interface belies a wealth of hidden functionality that can help you dart around a project like a fake US crime drama hacker. One key feature is support for tag files. Tag files are simple text files that list "language objects" alongside file names and locations. It's very much like an index in a book, except it's generally interpreted by software rather than human readers.

There are three aspects to using tags in Vim:

Read More →