6

I want to align my statements around a particular word or token.

Example:

import React          from 'react';
import { browserHistory, Router, Route } from 'react-router';
import Main           from './components/main';

In this case, I want my statements to be aligned around from word.

Like this

import React                             from 'react';
import { browserHistory, Router, Route } from 'react-router';
import Main                              from './components/main';

I have installed a plugin called tabular but I don't know how to align around a word. I can align around = or any other token but not around a word.

  • 4
    You should also see vim-easy-align. It provides an operator for aligning, which makes it possible to align using motions and text objects as targets. It also provides a live and interactive align operation which shows how the alignment will look for the provided options in realtime, LiveEasyAlign. – Karl Yngve Lervåg Jun 6 '16 at 12:41
8

The Tabular plugin works with regular expressions. So, you can give a word or a pattern, not just a single character.

:Tabularize /from/

will align in the way you wanted.

You can find a great tutorial about Tabular on Vimcasts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.