Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

file-line, to open path/to/file:23 directly

  • Loading branch information...
commit a0b8d77596330e240c4919bc01ed023e0ccde387 1 parent 5d3cb47
@jyurek authored
Showing with 38 additions and 0 deletions.
  1. +38 −0 vim/bundle/file-line/plugin/file:line.vim
View
38 vim/bundle/file-line/plugin/file:line.vim
@@ -0,0 +1,38 @@
+" Avoid installing twice or when in unsupported Vim version.
+if exists('g:loaded_file_line') || (v:version < 700)
+ finish
+endif
+let g:loaded_file_line = 1
+
+function! s:gotoline()
+ let file = bufname("%")
+
+ " :e command calls BufRead even though the file is a new one.
+ " As a workarround Jonas Pfenniger<jonas@pfenniger.name> added an
+ " AutoCmd BufRead, this will test if this file actually exists before
+ " searching for a file and line to goto.
+ if (filereadable(file))
+ return
+ endif
+
+ " Accept file:line:column: or file:line:column and file:line also
+ let names = matchlist( file, '\(.\{-1,}\):\(\d\+\)\(:\(\d*\):\?\)\?$')
+
+ if len(names) != 0 && filereadable(names[1])
+ let l:bufn = bufnr("%")
+ exec "keepalt edit " . names[1]
+ exec ":" . names[2]
+ exec ":bwipeout " l:bufn
+ if foldlevel(names[2]) > 0
+ exec ":foldopen!"
+ endif
+
+ if (names[4] != '')
+ exec "normal! " . names[4] . '|'
+ endif
+ endif
+
+endfunction
+
+autocmd! BufNewFile *:* nested call s:gotoline()
+autocmd! BufRead *:* nested call s:gotoline()
Please sign in to comment.
Something went wrong with that request. Please try again.