" Constants: {{{

let s:PUNCTUATIONS = {
      \   'before_space': [
      \     '!',
      \     ')',
      \     ',',
      \     '.',
      \     ':',
      \     ';',
      \     '?'
      \   ],
      \   'after_space': [
      \     '('
      \   ]
      \ }

let s:ISKEYWORD = printf('@,%s-%s', char2nr('0'), char2nr('9'))

" }}} Constants


function! wordword#break(text)
  let t = a:text
  let iskeyword = &l:iskeyword
  execute 'setlocal iskeyword=' . s:ISKEYWORD

  let t = substitute(t, '\>\<', '\0 ', 'g')

  if get(g:, 'wordword_break_on_punctuation')
    let pattern = printf('[%s]\<', join(s:PUNCTUATIONS.before_space, ''))
    let t = substitute(t, pattern, '\0 ', 'g')

    let pattern = printf('\>[%s]', join(s:PUNCTUATIONS.after_space, ''))
    let t = substitute(t, pattern, ' \0', 'g')
  endif

  let &l:iskeyword = iskeyword
  return t
endfunction

" Constants: {{{

let s:PUNCTUATIONS = {
      \   'before_space': [
      \     '!',
      \     ')',
      \     ',',
      \     '.',
      \     ':',
      \     ';',
      \     '?'
      \   ],
      \   'after_space': [
      \     '('
      \   ]
      \ }

let s:ISKEYWORD = printf('@,%s-%s', char2nr('0'), char2nr('9'))

" }}} Constants


function! wordword#break(text)
  let t = a:text
  let iskeyword = &l:iskeyword
  execute 'setlocal iskeyword=' . s:ISKEYWORD

  let t = substitute(t, '\>\<.', ' \0', 'g')

  if get(g:, 'wordword_break_on_punctuation')
    let pattern = printf('[%s]\<', join(s:PUNCTUATIONS.before_space, ''))
    let t = substitute(t, pattern, '\0 ', 'g')

    let pattern = printf('\>[%s]', join(s:PUNCTUATIONS.after_space, ''))
    let t = substitute(t, pattern, ' \0', 'g')
  endif

  let &l:iskeyword = iskeyword
  return t
endfunction

Fix substitution on old Vim version (7.3)
Fix substitution on old Vim version (7.3)

Seems Vim 7.3 handles zero-width match differently, the result of

    substitute(t, '\>\<', '\0 ', 'g')

produces 1 extra space for each match.

Anyway change the regex to `\>\<.`, do manipulation on next character
instead of on word boundary itself.

bootleq/vim-wordword