Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Enumerate and Align

Add a new field rank to each object, it starts at 1 and increments and align fields to look neat.

Before

[
  { word: "a", count: 2565 },
  { word: "and", count: 1777 },
  { word: "of", count: 1331 },
  { word: "that", count: 1263 },
  { word: "to", count: 1030 },
  { word: "in", count: 1027 },
  { word: "it", count: 754 },
  { word: "as", count: 730 },
  { word: "was", count: 687 },
  { word: "you", count: 652 },
  { word: "for", count: 630 },
];

After

[
  { rank:  1, word: "a",    count: 2565 },
  { rank:  2, word: "and",  count: 1777 },
  { rank:  3, word: "of",   count: 1331 },
  { rank:  4, word: "that", count: 1263 },
  { rank:  5, word: "to",   count: 1030 },
  { rank:  6, word: "in",   count: 1027 },
  { rank:  7, word: "it",   count:  754 },
  { rank:  8, word: "as",   count:  730 },
  { rank:  9, word: "was",  count:  687 },
  { rank: 10, word: "you",  count:  652 },
  { rank: 11, word: "for",  count:  630 },
];

Preview

Command

%s\{<enter>a rank: <ctrl-r>

#,<esc>%s |\d+<enter>&
  1. % selects full file
  2. Use s to enter select mode, which searches inside our selection and creates sub-selections based on a pattern
  3. Input \{ and then hit <enter>, which will place a cursor on every "{", creating many single-width selections
  4. a to go into insert mode after the "{"
  5. Input rank:
  6. <ctrl-r> followed by # inserts an increasing number for every selection starting with 1
  7. Input ,
  8. <esc> goes back to normal mode
  9. Use %s to enter select mode again
  10. Input |\d+ which is a regular expression selecting all spaces and numbers, then hit <enter>
  11. & to align all selections in columns, note that the numbers get right-aligned