Search notes:

vim script: split

" ..\run_.bat split
"

redir > split.out

" { Splitting with default pattern

let s:text = "  foo   bar\t\n  baz\n"
for word in split(s:text)
  echo 'word = ' . word
endfor
" word = foo
" word = bar
" word = baz

" }
" { Splitting with a pattern
let s:V = '0foo42bar13baz88'

let s:A = split(s:V, '\v\d+')

for i in s:A
  echo 'i = ' . i
endfor
" i = foo
" i = bar
" i = baz

" }
" { Splitting with a pattern (Keeping seperator)
let s:V = '0foo42bar13baz88'

let s:A = split(s:V, '\v\d+\zs')

for j in s:A
  echo 'j = ' . j
endfor
" j = 0
" j = foo42
" j = bar13
" j = baz88

" }
" { Splitting on newlines
echo '--------------------------------'

let s:dir_output = system('dir')

let s:dir = split(s:dir_output, "\n")

echo 'len(s:dir) = ' . len(s:dir)

echo

for f in s:dir
  if f =~? '^\d' && f !~? '<DIR>'
    echo 'f = ' .f
  endif
endfor

" }

q
Github repository about-vim, path: /vimscript/functions/split.vim

See also

Vim: built in functions
VIM script

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758184260, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/vim/script/vimscript/functions/split(103): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78