Repository: bogado/file-line
Branch: main
Commit: 559088afaf10
Files: 2
Total size: 3.1 KB
Directory structure:
gitextract_55bwf53o/
├── README.md
└── plugin/
└── file_line.vim
================================================
FILE CONTENTS
================================================
================================================
FILE: README.md
================================================
# File-line
### Plugin for vim to enable opening a file in a given line
When you open a `file:line`, for instance when coping and pasting from an error from your
compiler vim tries to open a file with a colon in its name.
Examples:
vim index.html:20
vim app/models/user.rb:1337
With this little script in your plugins folder if the stuff after the colon is a number and
a file exists with the name especified before the colon vim will open this file and take you
to the line you wished in the first place.
This script is licensed with GPLv3 and you can contribute to it on github at
[github.com/bogado/file-line](https://github.com/bogado/file-line).
## Install details
If you use `Bundle`, add this line to your `.vimrc`:
Bundle 'bogado/file-line'
And launch `:BundleInstall` in vim.
Or just copy the file into your plugins path (`$HOME/.vim/plugin` under unixes).
================================================
FILE: plugin/file_line.vim
================================================
" Avoid installing twice or when in unsupported Vim version.
if exists('g:loaded_file_line') || (v:version < 701)
finish
endif
let g:loaded_file_line = 1
" below regexp will separate filename and line/column number
" possible inputs to get to line 10 (and column 99) in code.cc are:
" * code.cc(10)
" * code.cc(10:99)
" * code.cc:10
" * code.cc:10:99
"
" closing braces/colons are ignored, so also acceptable are:
" * code.cc(10
" * code.cc:10:
let s:regexpressions = [ '\(.\{-1,}\)[(:]\(\d\+\)\%(:\(\d\+\):\?\)\?' ]
function! s:reopenAndGotoLine(file_name, line_num, col_num)
if !filereadable(a:file_name)
return
endif
let l:bufn = bufnr("%")
exec "keepalt edit " . fnameescape(a:file_name)
exec a:line_num
exec "normal! " . a:col_num . '|'
if foldlevel(a:line_num) > 0
exec "normal! zv"
endif
exec "normal! zz"
exec "bwipeout " l:bufn
exec "filetype detect"
endfunction
function! s:gotoline()
let file = bufname("%")
" :e command calls BufRead even though the file is a new one.
" As a workaround 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) || file == '')
return file
endif
let l:names = []
for regexp in s:regexpressions
let l:names = matchlist(file, regexp)
if ! empty(l:names)
let file_name = l:names[1]
let line_num = l:names[2] == ''? '0' : l:names[2]
let col_num = l:names[3] == ''? '0' : l:names[3]
call s:reopenAndGotoLine(file_name, line_num, col_num)
return file_name
endif
endfor
return file
endfunction
" Handle entry in the argument list.
" This is called via `:argdo` when entering Vim.
function! s:handle_arg()
let argname = expand('%')
let fname = s:gotoline()
if fname != argname
let argidx = argidx()
exec (argidx+1).'argdelete'
exec (argidx)'argadd' fnameescape(fname)
endif
endfunction
function! s:startup()
autocmd BufNewFile * nested call s:gotoline()
autocmd BufRead * nested call s:gotoline()
if argc() > 0
let argidx=argidx()
silent call s:handle_arg()
exec (argidx+1).'argument'
" Manually call Syntax autocommands, ignored by `:argdo`.
doautocmd Syntax
doautocmd FileType
endif
endfunction
if !isdirectory(expand("%:p"))
autocmd VimEnter * call s:startup()
endif
gitextract_55bwf53o/
├── README.md
└── plugin/
└── file_line.vim
Condensed preview — 2 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (4K chars).
[
{
"path": "README.md",
"chars": 896,
"preview": "# File-line\n\n### Plugin for vim to enable opening a file in a given line\n\nWhen you open a `file:line`, for instance when"
},
{
"path": "plugin/file_line.vim",
"chars": 2323,
"preview": "\" Avoid installing twice or when in unsupported Vim version.\nif exists('g:loaded_file_line') || (v:version < 701)\n\tfinis"
}
]
About this extraction
This page contains the full source code of the bogado/file-line GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 2 files (3.1 KB), approximately 1.1k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.