Writing whole alphabet in Vim

Using set nrformats+=alpha:

ia<Esc>qqylp<C-a>q24@q

Step by step:

ia<Esc>      " Start with 'a'
qqylp<C-a>q  " @q will duplicate the last character and increment it
24@q         " Append c..z

How about this command:

:put =join(map(range(char2nr('a'),char2nr('z')),'nr2char(v:val)'),'')

Collect the ASCII values of the characters in the range from a to z, then map them over the nr2char() function and insert the result into the current buffer with :put =.

When you leave out the enclosing join(,'') you get the characters on a separate line each.

See

  • :h nr2char(),
  • :h char2nr(),
  • :h :put,
  • and look up range(), map(), join() and friends in the list-functions table.

If your shell does brace expansion this is a pretty elegant solution:

:r !printf '\%s' {a..z}

:read! reads the output of an external command into the current buffer. In this case, it reads the output of the shell's printf applied to {a..z} after it's been expanded by the shell.

Tags:

Vim

Alphabet