k-takata / minpac

A minimal package manager for Vim 8+ (and Neovim)
835 stars 30 forks source link

WindowsにてVimパッケージインストール後のエラーメッセージ #151

Closed KatsuhiroArimoto closed 1 year ago

KatsuhiroArimoto commented 1 year ago

初めまして。 Windows 11にてVim 9.0の下でminpacを使用し、パッケージをインストールしたあと、qボタンを押すと以下のメッセージが出ました。

BufWinLeave Autocommands for "?*" の処理中にエラーが検出されました: E739: ディレクトリを作成できません: C:\Program Files\Vim/vimfiles/view E190: "C:\Program Files\Vim/vimfiles/view\~=+[minpac status]=" を書込み用として開けません

私がVimのスクリプトなどに詳しくないため、これがminpacのバグなのかどうか分かりかねますが、もし修正可能であればご対応いただけますと幸いです。 よろしくお願い申し上げます。

k-takata commented 1 year ago

minpacはどのようにインストールされましたか? また、.vimrc (あるいは _vimrc) はどこに置いてどのような内容になっていますか? 現象が再現可能な最小限の .vimrc と実行手順があるとありがたいです。

KatsuhiroArimoto commented 1 year ago

ご返信ありがとうございます。

minpacは、Git for Windowsをwingetでインストールし、そのGitを使ってC:\Users\ユーザ名\vimfiles\pack\minpac\opt\minpacにインストールしました(README.mdのとおりにインストールしました)。

_vimrcは、C:\Users\ユーザ名以下に置き、minpacに関係する部分は以下の通りです。 README.mdのサンプルをそのまま使っていると思います。

" Normally this if-block is not needed, because `:set nocp` is done
" automatically when .vimrc is found. However, this might be useful
" when you execute `vim -u .vimrc` from the command line.
if &compatible
  " `:set nocp` has many side effects. Therefore this should be done
  " only when 'compatible' is set.
  set nocompatible
endif

function! PackInit() abort
    packadd minpac  " Try to load minpac.
    call minpac#init()

    " minpac must have {'type': 'opt'} so that it can be loaded with `packadd`.
    call minpac#add('k-takata/minpac', {'type': 'opt'})

    " Add original plugins here.
    ...
endfunction

" Load the plugins right now. (optional)
"packloadall

" Define user commands for updating/cleaning the plugins.
" Each of them calls PackInit() to load minpac and register
" the information of plugins, then performs the task.
command! PackUpdate source $MYVIMRC | call PackInit() | call minpac#update()
command! PackClean  source $MYVIMRC | call PackInit() | call minpac#clean()
command! PackStatus packadd minpac | call minpac#init() | call minpac#status()

function! PackList(...)
    call PackInit()
    return join(sort(keys(minpac#getpluglist())), "\n")
endfunction

" Define a command to open a terminal window 
" at the directory of a specified plugin.
command! -nargs=1 -complete=custom,PackList
      \ PackOpenDir call PackInit() | call term_start(&shell,
      \    {'cwd': minpac#getpluginfo(<q-args>).dir,
      \     'term_finish': 'close'})
k-takata commented 1 year ago

minpacに関係する部分は以下の通りです。

一見 minpac に関係しない部分が影響していることもよくありますので、現象を再現できる最小限の .vimrc を用意していただくのが一番良いです。

BufWinLeave Autocommands for "?*" の処理中にエラーが検出されました:

BufWinLeave の設定が問題を引き起こしてそうです。

:verbose au BufWinLeave ?* を実行すると何が表示されますか。

KatsuhiroArimoto commented 1 year ago

現象を再現するvimrcの例は以下の通りでよろしいでしょうか。 私のvimrcから一部抜粋しました。

"---------------------------------------------------------------------------------------
" 基本設定
"---------------------------------------------------------------------------------------
set nowritebackup
set nobackup

"---------------------------------------------------------------------------------------
" 画面表示
"---------------------------------------------------------------------------------------
set title
set number
set visualbell

"---------------------------------------------------------------------------------------
" autocmd
"---------------------------------------------------------------------------------------
" 設定の保存と復元
augroup General
    autocmd!
    autocmd BufWinLeave ?* silent mkview
    autocmd BufWinEnter ?* silent loadview
augroup END

" auto reload .vimrc
augroup source_vimrc
    autocmd!
    "autocmd BufWritePost *vimrc source $MYVIMRC | set foldmethod=marker
    autocmd BufWritePost *vimrc source $MYVIMRC | set foldmethod=indent
    autocmd BufWritePost *gvimrc if has('gui_running') source $MYGVIMRC
augroup END

" auto comment off
augroup auto_comment_off
    autocmd!
    autocmd BufEnter * setlocal formatoptions-=r
    autocmd BufEnter * setlocal formatoptions-=o
augroup END

" HTML/XML閉じタグ自動補完
augroup my_xml
    autocmd!
    autocmd Filetype xml inoremap <buffer> </ </<C-x><C-o>
    autocmd Filetype html inoremap <buffer> </ </<C-x><C-o>
augroup END

" 編集箇所のカーソルを記憶
augroup red_hat
    autocmd!
    " In text files, always limit the width of text to 78 characters
    "autocmd BufRead *.txt set tw=78
    " When editing a file, always jump to the last cursor position
    autocmd BufReadPost *
    \ if line("'\"") > 0 && line ("'\"") <= line("$") |
    \   exe "normal! g'\"" |
    \ endif
augroup END

"---------------------------------------------------------------------------------------
" mimpac
"---------------------------------------------------------------------------------------
" Normally this if-block is not needed, because `:set nocp` is done
" automatically when .vimrc is found. However, this might be useful
" when you execute `vim -u .vimrc` from the command line.
if &compatible
  " `:set nocp` has many side effects. Therefore this should be done
  " only when 'compatible' is set.
  set nocompatible
endif

function! PackInit() abort
    packadd minpac  " Try to load minpac.
    call minpac#init()

    " minpac must have {'type': 'opt'} so that it can be loaded with `packadd`.
    call minpac#add('k-takata/minpac', {'type': 'opt'})

    " Add other plugins here.
    call minpac#add('vim-jp/syntax-vim-ex')
    call minpac#add('KatsuhiroArimoto/quantum_espresso-vim')
    call minpac#add('KatsuhiroArimoto/wannier90vim')
endfunction

" Load the plugins right now. (optional)
"packloadall

" Define user commands for updating/cleaning the plugins.
" Each of them calls PackInit() to load minpac and register
" the information of plugins, then performs the task.
command! PackUpdate source $MYVIMRC | call PackInit() | call minpac#update()
command! PackClean  source $MYVIMRC | call PackInit() | call minpac#clean()
command! PackStatus packadd minpac | call minpac#init() | call minpac#status()

function! PackList(...)
    call PackInit()
    return join(sort(keys(minpac#getpluglist())), "\n")
endfunction

" Define a command to open a terminal window 
" at the directory of a specified plugin.
command! -nargs=1 -complete=custom,PackList
      \ PackOpenDir call PackInit() | call term_start(&shell,
      \    {'cwd': minpac#getpluginfo(<q-args>).dir,
      \     'term_finish': 'close'})

また、:verbose au BufWinLeave ?*を実行すると以下が出力されました。

--- 自動コマンド ---
General  BufWinLeave
    ?*        silent mkview
        最後にセットしたスクリプト: ~\_vimrc 行 225
k-takata commented 1 year ago

_vimrc のここの設定が問題を引き起こしています。

" 設定の保存と復元
augroup General
    autocmd!
    autocmd BufWinLeave ?* silent mkview
    autocmd BufWinEnter ?* silent loadview
augroup END

mkview でビューを保存しようとしたときに、書き込み権限がないディレクトリにビューを保存しようとしてエラーになっています。

対処としてはいくつか考えられると思います。

  1. _vimrc 内で set viewdir=... を使って、ビューの保存先に書き込み可能なディレクトリを指定する。

  2. minpac の画面では mkview でビューを保存しないようにする。 autocmd の mkview の行を例えば以下のように変更。(動作未確認)

       autocmd BufWinLeave ?* if bufname() !~# '^\[minpac .*\]$' | silent mkview | fi
       autocmd BufWinEnter ?* silent loadview
  3. mkview を実行した際のエラーを無視する。 autocmd の mkview の行を例えば以下のように変更。(silent -> silent!)

       autocmd BufWinLeave ?* silent! mkview
       autocmd BufWinEnter ?* silent loadview
KatsuhiroArimoto commented 1 year ago

ご返信くださりありがとうございます。 上記の2の方法をためしたところ、エラーメッセージが消えました。 minpac本体とは関係のない質問で、大変お手数をおかけし、失礼いたしました。