Skip to content

Commit a720490

Browse files
Konfektvoldikss
authored andcommitted
Add mapping for current buffer directory toggle
Added a Vim function to get the current buffer directory and mapped F6 to toggle Floaterm with the current directory.
1 parent fd4bdd6 commit a720490

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,28 @@ nnoremap <silent> <F12> :FloatermToggle<CR>
378378
tnoremap <silent> <F12> <C-\><C-n>:FloatermToggle<CR>
379379
```
380380

381+
To toggle a term in the current buffer directory :
382+
383+
```vim
384+
function! s:get_dir(path) abort
385+
if isdirectory(a:path)
386+
let dir = fnamemodify(a:path, ':p')
387+
elseif filereadable(a:path)
388+
let dir = fnamemodify(a:path, ':p:h')
389+
else
390+
let dir = fnamemodify(getcwd(), ':p')
391+
endif
392+
let dir = fnamemodify(dir, ':~')
393+
let dir = escape(dir, ' %#|"')
394+
return dir
395+
endfunction
396+
397+
nnoremap <silent><expr> <F6> g:floaterm#buflist#curr() == -1 ?
398+
\ ':<c-u>FloatermNew --cwd=<C-R>=<sid>get_dir(expand("%"))<CR><CR>'
399+
\ : ':<c-u>FloatermToggle<CR>'
400+
tnoremap <silent> <F6> <C-\><C-n>:<c-u>FloatermToggle<cr>
401+
```
402+
381403
### Highlights
382404

383405
There are two `highlight-groups` to specify the color of floaterm (also the

0 commit comments

Comments
 (0)