Hacker Newsnew | comments | ask | jobs | submitlogin
HarrietTubgirl 653 days ago | link | parent

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

Boom!



tylerhobbs 652 days ago | link

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.

-----

johncoltrane 652 days ago | link

    set autochdir
does what you describe.

Thanks for the laggy SSH tip.

-----




Lists | RSS | Bookmarklet | Guidelines | FAQ | DMCA | News News | Feature Requests | Bugs | Y Combinator | Apply | Library

Search: