manually change to directory of current buffer

2 Points

marco marco

9 years ago

You know the :set autochdir setting which changes the CWD to the directory of the current buffer. But maybe you don't want to trigger this action automatically.

Here are two mapping to trigger the directory change manually.

In case the first one has problems with special characters in your path - the second one should work always.

nnoremap <yourkeys> :cd %:p:h<CR>
" OR
nnoremap <yourkeys> :set acd | set noacd<CR>
" OR
" create a toggle mapping and press twice
nnoremap <yourkeys> :set acd!<CR>