Created
August 26, 2020 15:25
-
-
Save Milly/1b97bef950e99146d28ae5788d8cd2cb to your computer and use it in GitHub Desktop.
Vim plugin that add chdir commands to current file's directory or fern path.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim plugin file - cdcurrent | |
" | |
" Purpose: Setup chdir commands | |
"============================================================================= | |
let s:is_windows = has('win32') || has('win64') | |
" cd to current file's directory | |
command! -bang Ccd call s:chdir_current('cd<bang>') | |
command! -bang Clcd call s:chdir_current('lcd<bang>') | |
command! -bang Ctcd call s:chdir_current('tcd<bang>') | |
function! s:chdir_current(cmd) abort | |
let path = expand('%') | |
if path =~# '^fern://' | |
let fri = fern#fri#parse(path) | |
let path = fern#fri#to#filepath(fern#fri#parse(fri)) | |
elseif path =~# '://' | |
echohl WarningMsg | |
echo "Path is URI: " .. path | |
echohl None | |
return | |
else | |
let path = fnamemodify(path, ':p:h') | |
endif | |
execute a:cmd fnameescape(path) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment