Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 31st, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Vimscript: regex works in :s but not in substitute()
  2. :redir => x|silent :ls|redir END
  3. :let y = substitute(x, ".*(".*").*", "1", "g")
  4.        
  5. let buflist=map(filter(range(1, bufnr('$')), 'buflisted(v:val)'), 'bufname(v:val)')
  6.        
  7. function BufName(bnr)
  8.     let bn=bufname(a:bnr)
  9.     let bt=getbufvar(a:bnr, '&buftype')
  10.     if empty(bn)
  11.         return (empty(bt)?('[No Name]'):('[Scratch]'))
  12.     elseif empty(bt)
  13.         " This won't produce names like ../file, while :ls will "
  14.         return fnamemodify(bn, ':~:.')
  15.     elseif bt is# 'help'
  16.         return fnamemodify(bn, ':t')
  17.     else
  18.         return bn
  19.     endif
  20. endfunction
  21.        
  22. let bufliststr=join(buflist, "n")
  23.        
  24. 1 #    "~/Session.vim"                line 5
  25. 2      "~/.vimrc"                     line 34
  26. 3      ".vim/vscripts/makesess.vim"   line 4
  27. 4      "~/Documents/vimcht"           line 62
  28. 5      "~/.fluxbox/startup"           line 5
  29. 6      "~/Documents/Notes"            line 2604
  30. 7      "~/Documents/bashcht"          line 21
  31. 8 %a   "junk"                         line 10
  32.        
  33. :let y = ""
  34. :let y = substitute(x, '[.]*("[.]*")[.]*', '1', "g")
  35.        
  36. "junk"
  37.        
  38. :let y = ""
  39. :let y = substitute(x, '[^n]*("[^n]*")[^n]*', '1', "g")
  40.        
  41. :let y = substitute(x, '[^"]*("[^"]+")[^"]*', ':tabe 1n', 'g')
  42.        
  43. :tabe "~/Session.vim"
  44. :tabe "~/.vimrc"
  45. :tabe ".vim/vscripts/makesess.vim"
  46. :tabe "~/Documents/vimcht"
  47. :tabe "~/.fluxbox/startup"
  48. :tabe "~/Documents/Notes"
  49. :tabe "~/Documents/bashcht"
  50. :tabe "junk"