0

OS X 10.11 adds a nice feature to Terminal.app that interprets control sequences of the form

ESC ] 6 ; file://hostname/<path-as-URL> BEL

as specifying the "document" which is currently being edited or viewed. As an example, entering

echo -e "\x1b]6;file://localhost/etc/passwd\a"

will cause the terminal title to display the filename passwd, which can be cmd+clicked on to get a breadcrumb trail (a feature of the "document title" in most file editors on OS X). The OS X default bashrc already uses this sequence to insert the current working directory into the window title.

I'd like to know how I can get Vim to output this particular escape sequence whenever it edits a new file (and, ideally, how to unset it once the editing stops - e.g. on quit or file change). Extensions to e.g. less and other programs would also be very helpful.

Although the URL technically has to be properly URL-encoded, I'm totally fine if it isn't - I don't usually edit files with particularly unusual filenames in Vim.

1 Answer 1

1

If you don't mind giving up the usual title handling in Vim, you can hijack that. It emits to the terminal, and can be adjusted to issue the appropriate sequences:

set t_ts=^[]6;file://localhost
set t_fs=^G^M
set title
autocmd BufEnter * let &titlestring = expand("%:p")

Use control+v and then esc to get the literal characters for the control characters shown above. A function around vim in your shell will wipe out the setting (the VimLeave autocmd I could not get to work in 7.3, and there's also the if-you-suspend vim problem).

function vim {
    command vim "$@"
    echo -ne "\033]6;\007"
}

:help title for details on title, or have a look in the Vim src/term.c file for the code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .