mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-23 17:49:57 +08:00
Improve shell layer key binding (#2409)
* Make SPC ' do not close terminal * Use q to hide shell instead of close terminal * Update documentation * Clear the cmdline when toggle shell windows * Add func to close vimfiler * Close terminal before close vimfiler * Cache shell default project root * Fix shell config * Fix default shell buffer nr * Fix ctrl+d in windows cmd
This commit is contained in:
parent
8e82c33889
commit
5ee5c57c8d
@ -11,9 +11,16 @@
|
|||||||
" @parentsection layers
|
" @parentsection layers
|
||||||
" SpaceVim uses deol.nvim for shell support in neovim and uses vimshell for
|
" SpaceVim uses deol.nvim for shell support in neovim and uses vimshell for
|
||||||
" vim. For more info, read |deol| and |vimshell|.
|
" vim. For more info, read |deol| and |vimshell|.
|
||||||
" @subsection variable
|
|
||||||
" default_shell
|
|
||||||
"
|
"
|
||||||
|
" @subsection variable
|
||||||
|
"
|
||||||
|
" default_shell: config the default shell to be used by shell layer.
|
||||||
|
"
|
||||||
|
" @subsection key bindings
|
||||||
|
" >
|
||||||
|
" SPC ' Open or switch to terminal windows
|
||||||
|
" q Hide terminal windows in normal mode
|
||||||
|
" <
|
||||||
|
|
||||||
let s:SYSTEM = SpaceVim#api#import('system')
|
let s:SYSTEM = SpaceVim#api#import('system')
|
||||||
|
|
||||||
@ -60,8 +67,7 @@ endfunction
|
|||||||
" FIXME:
|
" FIXME:
|
||||||
func! SpaceVim#layers#shell#terminal() abort
|
func! SpaceVim#layers#shell#terminal() abort
|
||||||
let line = getline('$')
|
let line = getline('$')
|
||||||
let pwd = getcwd()
|
if isdirectory(line[:-2])
|
||||||
if line ==# pwd . '>'
|
|
||||||
return "exit\<CR>"
|
return "exit\<CR>"
|
||||||
endif
|
endif
|
||||||
return "\<C-d>"
|
return "\<C-d>"
|
||||||
@ -70,7 +76,6 @@ func! SpaceVim#layers#shell#ctrl_u() abort
|
|||||||
let line = getline('$')
|
let line = getline('$')
|
||||||
let prompt = getcwd() . '>'
|
let prompt = getcwd() . '>'
|
||||||
return repeat("\<BS>", len(line) - len(prompt) + 2)
|
return repeat("\<BS>", len(line) - len(prompt) + 2)
|
||||||
return "\<C-u>"
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
func! SpaceVim#layers#shell#ctrl_w() abort
|
func! SpaceVim#layers#shell#ctrl_w() abort
|
||||||
@ -84,11 +89,16 @@ endfunction
|
|||||||
let s:default_shell = 'terminal'
|
let s:default_shell = 'terminal'
|
||||||
let s:default_position = 'top'
|
let s:default_position = 'top'
|
||||||
let s:default_height = 30
|
let s:default_height = 30
|
||||||
|
" the shell should be cached base on the root of a project, cache the terminal
|
||||||
|
" buffer id in: s:shell_cached_br
|
||||||
|
let s:enable_project_shell = 1
|
||||||
|
let s:shell_cached_br = {}
|
||||||
|
|
||||||
function! SpaceVim#layers#shell#set_variable(var) abort
|
function! SpaceVim#layers#shell#set_variable(var) abort
|
||||||
let s:default_shell = get(a:var, 'default_shell', 'terminal')
|
let s:default_shell = get(a:var, 'default_shell', 'terminal')
|
||||||
let s:default_position = get(a:var, 'default_position', 'top')
|
let s:default_position = get(a:var, 'default_position', 'top')
|
||||||
let s:default_height = get(a:var, 'default_height', 30)
|
let s:default_height = get(a:var, 'default_height', 30)
|
||||||
|
let s:enable_project_shell = get(a:var, 'enable_project_shell', 1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#layers#shell#get_options() abort
|
function! SpaceVim#layers#shell#get_options() abort
|
||||||
@ -97,15 +107,26 @@ function! SpaceVim#layers#shell#get_options() abort
|
|||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:shell_win_nr = 0
|
let s:shell_win_nr = -1
|
||||||
|
let s:term_buf_nr = -1
|
||||||
|
" shell windows shoud be toggleable, and can be hide.
|
||||||
function! s:open_default_shell() abort
|
function! s:open_default_shell() abort
|
||||||
if s:shell_win_nr != 0 && getwinvar(s:shell_win_nr, '&buftype') ==# 'terminal' && &buftype !=# 'terminal'
|
if s:shell_win_nr != 0 && getwinvar(s:shell_win_nr, '&buftype') ==# 'terminal' && &buftype !=# 'terminal'
|
||||||
exe s:shell_win_nr . 'wincmd w'
|
exe s:shell_win_nr . 'wincmd w'
|
||||||
startinsert
|
" fuck gvim bug, startinsert do not work in gvim
|
||||||
|
if has('nvim')
|
||||||
|
startinsert
|
||||||
|
else
|
||||||
|
normal! a
|
||||||
|
endif
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
if &buftype ==# 'terminal'
|
if &buftype ==# 'terminal'
|
||||||
bwipeout! %
|
if has('nvim')
|
||||||
|
startinsert
|
||||||
|
else
|
||||||
|
normal! a
|
||||||
|
endif
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let cmd = s:default_position ==# 'top' ?
|
let cmd = s:default_position ==# 'top' ?
|
||||||
@ -119,6 +140,16 @@ function! s:open_default_shell() abort
|
|||||||
if lines < winheight(0) && (s:default_position ==# 'top' || s:default_position ==# 'bottom')
|
if lines < winheight(0) && (s:default_position ==# 'top' || s:default_position ==# 'bottom')
|
||||||
exe 'resize ' . lines
|
exe 'resize ' . lines
|
||||||
endif
|
endif
|
||||||
|
if bufexists(s:term_buf_nr)
|
||||||
|
exe 'silent b' . s:term_buf_nr
|
||||||
|
" clear the message
|
||||||
|
if has('nvim')
|
||||||
|
startinsert
|
||||||
|
else
|
||||||
|
normal! a
|
||||||
|
endif
|
||||||
|
return
|
||||||
|
endif
|
||||||
if s:default_shell ==# 'terminal'
|
if s:default_shell ==# 'terminal'
|
||||||
if exists(':terminal')
|
if exists(':terminal')
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
@ -134,6 +165,8 @@ function! s:open_default_shell() abort
|
|||||||
stopinsert
|
stopinsert
|
||||||
startinsert
|
startinsert
|
||||||
endif
|
endif
|
||||||
|
let s:term_buf_nr = bufnr('%')
|
||||||
|
call extend(s:shell_cached_br, {getcwd() : s:term_buf_nr})
|
||||||
else
|
else
|
||||||
if s:SYSTEM.isWindows
|
if s:SYSTEM.isWindows
|
||||||
let shell = empty($SHELL) ? 'cmd.exe' : $SHELL
|
let shell = empty($SHELL) ? 'cmd.exe' : $SHELL
|
||||||
@ -144,11 +177,11 @@ function! s:open_default_shell() abort
|
|||||||
endif
|
endif
|
||||||
let s:shell_win_nr = winnr()
|
let s:shell_win_nr = winnr()
|
||||||
let w:shell_layer_win = 1
|
let w:shell_layer_win = 1
|
||||||
setlocal nobuflisted
|
setlocal nobuflisted nonumber norelativenumber
|
||||||
" use q to close terminal buffer in vim, if vimcompatible mode is not
|
" use q to hide terminal buffer in vim, if vimcompatible mode is not
|
||||||
" enabled, and smart quit is on.
|
" enabled, and smart quit is on.
|
||||||
if g:spacevim_windows_smartclose == 0 && !g:spacevim_vimcompatible
|
if g:spacevim_windows_smartclose == 0 && !g:spacevim_vimcompatible
|
||||||
nnoremap <buffer><silent> q :bd!<CR>
|
nnoremap <buffer><silent> q :hide<CR>
|
||||||
endif
|
endif
|
||||||
startinsert
|
startinsert
|
||||||
else
|
else
|
||||||
@ -159,3 +192,9 @@ function! s:open_default_shell() abort
|
|||||||
imap <buffer> <C-d> exit<esc><Plug>(vimshell_enter)
|
imap <buffer> <C-d> exit<esc><Plug>(vimshell_enter)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#layers#shell#close_terminal()
|
||||||
|
if bufexists(s:term_buf_nr)
|
||||||
|
exe 'silent bd!' . s:term_buf_nr
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
@ -23,10 +23,10 @@ let g:vimfiler_ignore_pattern = get(g:, 'vimfiler_ignore_pattern', [
|
|||||||
\])
|
\])
|
||||||
|
|
||||||
if has('mac')
|
if has('mac')
|
||||||
let g:vimfiler_quick_look_command =
|
let g:vimfiler_quick_look_command =
|
||||||
\ get(g:, 'vimfiler_quick_look_command', 'qlmanage -p')
|
\ get(g:, 'vimfiler_quick_look_command', 'qlmanage -p')
|
||||||
else
|
else
|
||||||
let g:vimfiler_quick_look_command =
|
let g:vimfiler_quick_look_command =
|
||||||
\ get(g:, 'vimfiler_quick_look_command', 'gloobus-preview')
|
\ get(g:, 'vimfiler_quick_look_command', 'gloobus-preview')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -65,8 +65,16 @@ augroup vfinit
|
|||||||
au!
|
au!
|
||||||
autocmd FileType vimfiler call s:vimfilerinit()
|
autocmd FileType vimfiler call s:vimfilerinit()
|
||||||
autocmd BufEnter * nested if (!has('vim_starting') && winnr('$') == 1 && &filetype ==# 'vimfiler') |
|
autocmd BufEnter * nested if (!has('vim_starting') && winnr('$') == 1 && &filetype ==# 'vimfiler') |
|
||||||
\ q | endif
|
\ call s:close_last_vimfiler_windows() | endif
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
" in this function, we should check if shell terminal still exists,
|
||||||
|
" then close the terminal job before close vimfiler
|
||||||
|
function! s:close_last_vimfiler_windows() abort
|
||||||
|
call SpaceVim#layers#shell#close_terminal()
|
||||||
|
q
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:vimfilerinit()
|
function! s:vimfilerinit()
|
||||||
setl nonumber
|
setl nonumber
|
||||||
setl norelativenumber
|
setl norelativenumber
|
||||||
|
@ -1324,9 +1324,17 @@ SHELL *SpaceVim-layer-shell*
|
|||||||
|
|
||||||
SpaceVim uses deol.nvim for shell support in neovim and uses vimshell for vim.
|
SpaceVim uses deol.nvim for shell support in neovim and uses vimshell for vim.
|
||||||
For more info, read |deol| and |vimshell|.
|
For more info, read |deol| and |vimshell|.
|
||||||
VARIABLE
|
|
||||||
default_shell
|
|
||||||
|
|
||||||
|
VARIABLE
|
||||||
|
|
||||||
|
default_shell: config the default shell to be used by shell layer.
|
||||||
|
|
||||||
|
KEY BINDINGS
|
||||||
|
|
||||||
|
>
|
||||||
|
SPC ' Open or switch to terminal windows
|
||||||
|
q Hide terminal windows in normal mode
|
||||||
|
<
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
TMUX *SpaceVim-layer-tmux*
|
TMUX *SpaceVim-layer-tmux*
|
||||||
|
@ -61,7 +61,7 @@ The default shell is quickly accessible via a the default shortcut key `SPC '`.
|
|||||||
| -------- | ---------------------------------- |
|
| -------- | ---------------------------------- |
|
||||||
| `SPC '` | 打开或跳至已打开的终端窗口 |
|
| `SPC '` | 打开或跳至已打开的终端窗口 |
|
||||||
| `Ctrl-d` | 输入模式下关闭终端窗口 |
|
| `Ctrl-d` | 输入模式下关闭终端窗口 |
|
||||||
| `q` | Normal 模式下关闭终端窗口 |
|
| `q` | Normal 模式下隐藏终端窗口 |
|
||||||
| `<Esc>` | 从 Terminal 模式切换到 Normal 模式 |
|
| `<Esc>` | 从 Terminal 模式切换到 Normal 模式 |
|
||||||
| `Ctrl-h` | 切换到左侧窗口 |
|
| `Ctrl-h` | 切换到左侧窗口 |
|
||||||
| `Ctrl-j` | 切换到上方窗口 |
|
| `Ctrl-j` | 切换到上方窗口 |
|
||||||
|
@ -62,7 +62,7 @@ in percents with the variable `default_height`. Default value is 30.
|
|||||||
| ----------- | ---------------------------------------- |
|
| ----------- | ---------------------------------------- |
|
||||||
| `SPC '` | Open or switch to the terminal windows |
|
| `SPC '` | Open or switch to the terminal windows |
|
||||||
| `Ctrl-d` | Close terminal windows in terminal mode |
|
| `Ctrl-d` | Close terminal windows in terminal mode |
|
||||||
| `q` | Close terminal windows in Normal mode |
|
| `q` | Hide terminal windows in Normal mode |
|
||||||
| `<Esc>` | Switch to Normal mode from terminal mode |
|
| `<Esc>` | Switch to Normal mode from terminal mode |
|
||||||
| `Ctrl-h` | Switch to the windows on the left |
|
| `Ctrl-h` | Switch to the windows on the left |
|
||||||
| `Ctrl-j` | Switch to the windows below |
|
| `Ctrl-j` | Switch to the windows below |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user