Hacker News new | comments | show | ask | jobs | submit login

I've come and gone with various vim config changes, but this is the one non-standard one I've stuck with:

au! BufRead,BufNewFile * lcd %:p:h

This makes it so that when you open a buffer, you cd to the current directory (only for that window), so you can quickly open files in that directory.

[% is the current file relative to pwd, :p converts to a full path, :h takes off a path component, lcd does a cd but only for the current window]

Another tip is that when your internet connection sucks enough for SSH lag (tethered, free wifi, whatever), you can edit a file locally and have vim do the SCP back when you write:

:e scp://you@somewhere/path


A nice alternative is to do:

  " Allow easy navigation to relative files
  cmap %/ %:p:h/
This basically replaces everything before the slash with the directory of the file you're editing. That way, you don't have to necessarily cd, but can easily open files near the one you're currently editing. You can just do ":e %/foo.txt" to open foo.txt in the same directory.

    set autochdir
does what you describe.

Thanks for the laggy SSH tip.

Applications are open for YC Summer 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact