Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

シェル・スクリプトの折り畳み設定 #1399

Open
iranoan opened this issue Nov 3, 2022 · 4 comments
Open

シェル・スクリプトの折り畳み設定 #1399

iranoan opened this issue Nov 3, 2022 · 4 comments

Comments

@iranoan
Copy link

iranoan commented Nov 3, 2022

質問の内容

$ vim a.sh
の様に起動時にシェル・スクリプトのファイル (以下単にスクリプト) を指定した場合は ~/.vim/vimrc に :help sh.vim に有るように let g:sh_fold_enabled = 7 等を指定しても無視されてしまいます
$ vim
やスクリプト以外を引数として起動し、その後スクリプトを開いた時は問題ありません

~/.vim/vimrc の内容が下記の時

set background=dark
colorscheme desert
filetype plugin on
syntax enable
set foldcolumn=4 foldmethod=syntax foldlevel=9
let g:sh_fold_enabled = 7
  • スクリプトを引数として起動
  • 引数なしで起動後にスクリプトを開いた時

の動画を添付します
sh_fold_enabled

vimrc の設定の多くは、折り畳みの有無を判り易くするために加えただけで、再現条件そのものには関係がありません

これは不具合扱いでしょうか?
またどのような回避策が正解でしょうか?

私の環境では --startuptime 付きで起動して、読み込み順序を確認してみると、次の様に vimrc より先に $VIMRUNTIME/syntax/sh.vim が読み込まれているのが原因と考え、~/.vim/filetype.vim に記載して回避したのですが…

008.545 000.124 000.124: sourcing /home/user/.vim/filetype.vim
<snip>
021.228 003.236 003.236: sourcing /usr/share/vim/vim90/syntax/sh.vim
021.733 017.702 001.898: sourcing /usr/share/vim/vim90/syntax/syntax.vim
021.767 018.682 000.453: sourcing /etc/vim/vimrc
022.544 000.018 000.018: sourcing /home/user/.vim/filetype.vim
<snip>
028.677 002.981 002.981: sourcing /usr/share/vim/vim90/syntax/sh.vim
028.812 004.255 000.455: sourcing /usr/share/vim/vim90/syntax/syntax.vim
037.170 015.311 010.919: sourcing ~/.vim/vimrc
<snip>
090.112 004.001 004.001: sourcing /usr/share/vim/vim90/syntax/sh.vim
<snip>
211.287 004.630 004.630: sourcing /usr/share/vim/vim90/syntax/sh.vim

Vimのバージョン

$ vim --version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Aug 23 2022 20:18:58)
適用済パッチ: 1-242
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
Huge 版 with GTK3 GUI. 機能の一覧 有効(+)/無効(-)

OSの種類/ディストリ/バージョン

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.10
Release: 22.10
Codename: kinetic
$ uname -a
Linux xxxx 5.19.0-23-generic #24-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct 14 15:39:57 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

@h-east
Copy link
Member

h-east commented Nov 4, 2022

--startuptimeは指定ファイルに追記されるので、以下の手順で取得した情報を貼り付けてもらえますか。
(同じファイルが何度も読み込まれているのが、追記のものなのか本当に複数回読み込まれているのか判断がつかないため)

読み込んだスクリプトの一覧がクリップボードにコピーされます。(@*@+かも)

:redir @*
:scriptnames
:redir END

私の環境では真っ先に自分の vimrc (Linux: ~/.vimrc, Windows: ~/_vimrc)が読み込まれているのでこのIssueの件は発生しないですね。

@iranoan
Copy link
Author

iranoan commented Nov 4, 2022

--startuptimeは指定ファイルに追記されるので、以下の手順で取得した情報を貼り付けてもらえますか。
(同じファイルが何度も読み込まれているのが、追記のものなのか本当に複数回読み込まれているのか判断がつかないため)

私も前々から不思議に思っていたのですが、幾つかのファイルは複数回読み込まれています
しかし前回の書き込みは一回分です

念の為

$ vim a.sh

直後の

:put=execute('scriptnames')

の結果は次のとおりです

1: /etc/vim/vimrc
2: /usr/share/vim/vim90/debian.vim
3: /usr/share/vim/vim90/syntax/syntax.vim
4: /usr/share/vim/vim90/syntax/synload.vim
5: /usr/share/vim/vim90/syntax/syncolor.vim
6: /usr/share/vim/vim90/colors/lists/default.vim
7: /usr/share/vim/vim90/filetype.vim
8: /usr/share/vim/vim90/autoload/dist/ft.vim
9: /usr/share/vim/vim90/syntax/sh.vim
10: ~/vim/vimrc
11: /usr/share/vim/vim90/colors/desert.vim
12: /usr/share/vim/vim90/ftplugin.vim
13: /usr/share/vim/vim90/syntax/nosyntax.vim
14: /usr/share/vim/vim90/plugin/getscriptPlugin.vim
15: /usr/share/vim/vim90/plugin/gzip.vim
16: /usr/share/vim/vim90/plugin/logiPat.vim
17: /usr/share/vim/vim90/plugin/manpager.vim
18: /usr/share/vim/vim90/plugin/matchparen.vim
19: /usr/share/vim/vim90/plugin/netrwPlugin.vim
20: /usr/share/vim/vim90/plugin/rrhelper.vim
21: /usr/share/vim/vim90/plugin/spellfile.vim
22: /usr/share/vim/vim90/plugin/tarPlugin.vim
23: /usr/share/vim/vim90/plugin/tohtml.vim
24: /usr/share/vim/vim90/plugin/vimballPlugin.vim
25: /usr/share/vim/vim90/plugin/zipPlugin.vim
26: /usr/share/vim/vim90/ftplugin/sh.vim

やはり私の環境では ~/.vim/vimrc より先に $VIMRUNTIME/syntax/sh.vim が読み込まれるようです

何度がOSのアップグレードはしていますが、ディストリビューション公式のパッケージを普通に使っているだけで、このテスト用の設定ファイル群には filetypes.vim 等も置いていません

@h-east
Copy link
Member

h-east commented Nov 4, 2022

私の環境はUbuntu 20.04です。/etc/vim/vimrcに以下の行があります。

runtime! debian.vim

こちらではdebian.vimないですが、 @iranoan さんの環境では存在していて読み込んでいますね。そのファイルの内容を貼り付けをお願いします。

@iranoan
Copy link
Author

iranoan commented Nov 4, 2022

/usr/share/vim/vim90/debian.vim の内容です

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible	" Use Vim defaults instead of 100% vi compatibility
set backspace=indent,eol,start	" more powerful backspacing

" Now we set some defaults for the editor
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time

" modelines have historically been a source of security/resource
" vulnerabilities -- disable by default, even when 'nocompatible' is set
set nomodeline

" Suffixes that get lower priority when doing tab completion for filenames.
" These are files we are not likely to want to edit or read.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc

" We know xterm-debian is a color terminal
if &term =~ "xterm-debian" || &term =~ "xterm-xfree86"
  set t_Co=16
  set t_Sf=�[3%dm
  set t_Sb=�[4%dm
endif

" Some Debian-specific things
if has('gui')
  " Must define this within the :if so it does not cause problems with
  " vim-tiny (which does not have +eval)
  function! <SID>MapExists(name, modes)
    for mode in split(a:modes, '\zs')
      if !empty(maparg(a:name, mode))
        return 1
      endif
    endfor
    return 0
  endfunction

  " Make shift-insert work like in Xterm
  autocmd GUIEnter * if !<SID>MapExists("<S-Insert>", "nvso") | execute "map <S-Insert> <MiddleMouse>" | endif
  autocmd GUIEnter * if !<SID>MapExists("<S-Insert>", "ic") | execute "map! <S-Insert> <MiddleMouse>" | endif
endif

" Set paper size from /etc/papersize if available (Debian-specific)
if filereadable("/etc/papersize")
  let s:papersize = matchstr(readfile('/etc/papersize', '', 1), '\p*')
  if strlen(s:papersize)
    exe "set printoptions+=paper:" . s:papersize
  endif
endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants