-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.terminal.vim
51 lines (46 loc) · 1.7 KB
/
init.terminal.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Terminal
" Usage:
" <M-[> Go to terminal Normal mode
" vim and not neovim:
" <C-W> . Send <C-w> to terminal
if exists('g:nvim')
autocmd TermOpen * setlocal nonumber norelativenumber
" NOTE: added lazygit check to avoid lua error
" NOTE: added "silent!" to avoid error when FZF terminal window is closed.
autocmd TermClose * if &filetype != 'lazygit' && !v:event.status | silent! exe 'bdelete! '..expand('<abuf>') | endif
else
autocmd TerminalWinOpen * setlocal nonumber norelativenumber
endif
" Start terminal in insert mode when switching to it
autocmd BufEnter * if &buftype == 'terminal' | set nonumber norelativenumber | :startinsert | endif
" Close terminal buffers if the job exited without error
" Open terminal with opt+F12 (just like in JetBrains).
function! OpenTerminal()
if exists('g:nvim')
split term://zsh
else
terminal ++close
endif
resize 10
endfunction
" Open in current buffer's directory
function! RevealInTerminal()
let l:dir = expand('%:p:h')
if exists('g:nvim')
below new
call termopen([&shell], {'cwd': expand('%:p:h') })
normal i
else
terminal ++close
" XXX Can't figure out how to change the diretory from within a function.
" So we have to do it in the mapping.
endif
resize 10
endfunction
" Convenience map of <M-[> for escaping to normal mode, which is easier to
" press than <C-\><C-N>
call MapKey('<M-[>', '', ['tnoremap'])
" For <C-/> to work in FZF window to toggle preview side view
" NOTE: Doesn't work in MacVim (and other UIs may beep); using <C-_> is better
tmap <C-/> <C-_>