Skip to content

Instantly share code, notes, and snippets.

@bignimbus
Last active October 12, 2022 11:19
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bignimbus/1da46a18416da4119778 to your computer and use it in GitHub Desktop.
Save bignimbus/1da46a18416da4119778 to your computer and use it in GitHub Desktop.
Set iTerm2 title to current buffer in vim
" Set the title of the Terminal to the currently open file
function! SetTerminalTitle()
let titleString = expand('%:t')
if len(titleString) > 0
let &titlestring = expand('%:t')
" this is the format iTerm2 expects when setting the window title
let args = "\033];".&titlestring."\007"
let cmd = 'silent !echo -e "'.args.'"'
execute cmd
redraw!
endif
endfunction
autocmd BufEnter * call SetTerminalTitle()
@rparker
Copy link

rparker commented Aug 28, 2020

This works, but adds ~1,200 ms to my vim startup time.
I measured with "vim --startuptime vim.log somefile.txt"

@PKostovic
Copy link

Thank you, this saved me a bunch of time tinkering with it myself and made life a little bit easier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment