From af1b4d1f294b79049b5a15f2a1f5defc264c8f01 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Wed, 4 Sep 2019 22:56:45 +0800 Subject: [PATCH] add fish script support (#3033) --- autoload/SpaceVim/layers/edit.vim | 8 +++-- autoload/SpaceVim/layers/lang/python.vim | 4 ++- autoload/SpaceVim/layers/lang/sh.vim | 43 +++++++++++++++--------- autoload/SpaceVim/mapping/guide.vim | 3 ++ docs/cn/layers/lang/sh.md | 2 +- docs/layers/lang/sh.md | 2 +- 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 2b01a876d..4107e7ea1 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -608,12 +608,14 @@ endif augroup spacevim_layer_edit au! - autocmd BufNewFile * call add_buffer_head() + autocmd FileType * call add_buffer_head() augroup END let s:ft_head_tp = {} function! s:add_buffer_head() abort - if has_key(s:ft_head_tp, &ft) - call setline(1, s:ft_head_tp[&ft]) + if has_key(s:ft_head_tp, &ft) && getline(1) == '' && line('$') == 1 + let head = s:ft_head_tp[&ft] + call setline(1, head) + call cursor(len(head), 0) endif endfunction diff --git a/autoload/SpaceVim/layers/lang/python.vim b/autoload/SpaceVim/layers/lang/python.vim index e1f8f03e2..1552b4f40 100644 --- a/autoload/SpaceVim/layers/lang/python.vim +++ b/autoload/SpaceVim/layers/lang/python.vim @@ -70,7 +70,9 @@ function! SpaceVim#layers#lang#python#config() abort call SpaceVim#layers#edit#add_ft_head_tamplate('python', \ ['#!/usr/bin/env python', \ '# -*- coding: utf-8 -*-', - \ ''] + \ '', + \ '' + \ ] \ ) if executable('ipython') call SpaceVim#plugins#repl#reg('python', 'ipython --no-term-title') diff --git a/autoload/SpaceVim/layers/lang/sh.vim b/autoload/SpaceVim/layers/lang/sh.vim index 82b47e174..e9f2ab835 100644 --- a/autoload/SpaceVim/layers/lang/sh.vim +++ b/autoload/SpaceVim/layers/lang/sh.vim @@ -7,14 +7,15 @@ "============================================================================= function! SpaceVim#layers#lang#sh#plugins() abort - let l:plugins = [] - call add(l:plugins, ['chrisbra/vim-zsh', { 'on_ft' : 'zsh' }]) - if get(g:, 'spacevim_enable_ycm') == 1 - call add(l:plugins, ['Valodim/vim-zsh-completion', { 'on_ft' : 'zsh' }]) - else - call add(l:plugins, ['zchee/deoplete-zsh', { 'on_ft' : 'zsh' }]) - endif - return l:plugins + let l:plugins = [] + call add(l:plugins, ['chrisbra/vim-zsh', { 'on_ft' : 'zsh' }]) + call add(l:plugins, ['dag/vim-fish', { 'merged' : 0 }]) + if get(g:, 'spacevim_enable_ycm') == 1 + call add(l:plugins, ['Valodim/vim-zsh-completion', { 'on_ft' : 'zsh' }]) + else + call add(l:plugins, ['zchee/deoplete-zsh', { 'on_ft' : 'zsh' }]) + endif + return l:plugins endfunction function! SpaceVim#layers#lang#sh#config() abort @@ -22,19 +23,29 @@ function! SpaceVim#layers#lang#sh#config() abort let g:zsh_fold_enable = 1 " }}} - call SpaceVim#layers#edit#add_ft_head_tamplate('sh', - \ ['#!/usr/bin/env bash', - \ ''] - \ ) + call SpaceVim#layers#edit#add_ft_head_tamplate('sh', + \ ['#!/usr/bin/env bash', + \ '', + \ '' + \ ] + \ ) call SpaceVim#layers#edit#add_ft_head_tamplate('zsh', [ - \ '#!/usr/bin/env zsh', - \ '' - \ ]) + \ '#!/usr/bin/env zsh', + \ '', + \ '' + \ ]) + call SpaceVim#layers#edit#add_ft_head_tamplate('fish', [ + \ '#!/usr/bin/env fish', + \ '', + \ '' + \ ]) augroup spacevim_layer_lang_sh autocmd! autocmd FileType sh setlocal omnifunc=SpaceVim#plugins#bashcomplete#omnicomplete augroup END call SpaceVim#mapping#gd#add('sh', function('s:go_to_def')) + call SpaceVim#mapping#gd#add('zsh', function('s:go_to_def')) + call SpaceVim#mapping#gd#add('fish', function('s:go_to_def')) call SpaceVim#mapping#space#regesit_lang_mappings('sh', function('s:language_specified_mappings')) endfunction function! s:language_specified_mappings() abort @@ -49,7 +60,7 @@ function! s:language_specified_mappings() abort endfunction function! s:go_to_def() abort - if SpaceVim#layers#lsp#check_filetype('sh') + if SpaceVim#layers#lsp#check_filetype(&filetype) call SpaceVim#lsp#go_to_def() endif endfunction diff --git a/autoload/SpaceVim/mapping/guide.vim b/autoload/SpaceVim/mapping/guide.vim index 38bfb9944..40032e27f 100644 --- a/autoload/SpaceVim/mapping/guide.vim +++ b/autoload/SpaceVim/mapping/guide.vim @@ -599,6 +599,9 @@ function! s:winclose() abort " {{{ let s:gwin = -1 noautocmd execute s:winnr.'wincmd w' call winrestview(s:winv) + if exists('*nvim_open_win') + doautocmd WinEnter + endif endif call s:remove_cursor_highlight() endfunction " }}} diff --git a/docs/cn/layers/lang/sh.md b/docs/cn/layers/lang/sh.md index 06efd1818..0cd26fa6d 100644 --- a/docs/cn/layers/lang/sh.md +++ b/docs/cn/layers/lang/sh.md @@ -18,7 +18,7 @@ lang: cn ## 模块简介 -这一模块为 SpaceVim 提供了 Shell Script 开发支持。Shell Script 是指 Bash script 和 Zsh script。 +这一模块为 SpaceVim 提供了 Shell Script 开发支持。Shell Script 是指 bash script、zsh script 和 fish script。 ## 功能特性 diff --git a/docs/layers/lang/sh.md b/docs/layers/lang/sh.md index 53931e495..27b0bfb9e 100644 --- a/docs/layers/lang/sh.md +++ b/docs/layers/lang/sh.md @@ -18,7 +18,7 @@ description: "Shell script development layer, provides autocompletion, syntax ch ## Description -This layer is for shell script development. Shell script includes bash script and zsh script. +This layer is for shell script development. Shell script includes bash, zsh and fish script. ## Features