VIM add numbers to range
William McKeehan
William McKeehan
May 10, 2023

VIM add numbers to range

VIM UL to OL

VIM add numbers to range

To number a section, press V to select the first line, then press j to extend the selection down until all required lines are selected. Then type the following command (do not type '<,'> as that is inserted by Vim):

:'<,'>s/^/\=printf("%d.\t", line(".") - line("'<") + 1)

To change an unordered list (in Markdown) to an ordered list, select the items in the unordered list, then execute:

:'<,'>s/^- /\=printf("%d.\t", line(".") - line("'<") + 1)

Source: https://vim.fandom.com/wiki/Insert_line_numbers