VimはVexploreと端末を使って自動的に起動します。

VimはVexploreと端末を使って自動的に起動します。

ほとんどの状況では、既存のIDEのように動作するようにvimを設定したいと思います。私がしたいのは、vimコマンドを入力すると次のように開くことです。

ビーム窓

問題は、次のように開くことです。

vim デモ

端末は自動的に起動しますが、前のウィンドウで起動したいと思います。私は文書を読もうとしましたが、文書を読んでコードに入れる方法がわかりません。 vimrcのほとんどのコードはコピー&ペーストされたコードであり、いくつかの基本は既知です。最初の写真のように自動的に起動するようにしたいと思います。

また、vimで可能であるかどうかわからない問題の1つは、NetRWでバッファをクリックするとディレクトリツリーが消去され、空のバッファが表示されることがあることです。特定のコマンドがターミナルバッファとディレクトリツリーのリストを妨げないように無効にする方法はありますか?たとえば、ファイルを開こうとしたときに最後のバッファがターミナルバッファの場合、現在のバッファ(ターミナル)を保存してファイルを開くかどうかを尋ねるメッセージが表示されます。非端末領域のバッファリングについてよりスマートになりたい。端末の代わりに。デフォルトでは、コマンド入力を除いて端末は完全に無視されます。

ここに私のvimrcがあります。コピーして貼り付けただけなので混乱することもあります。

set mouse=a
set number
imap jj <Esc>
set autochdir
map <Tab> <C-W>W:cd %:p:h<CR>:<CR>
map <C-l> :q!<CR>
map <C-t> :term bash<CR>
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Using a non-master branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }

" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'

" Initialize plugin system
call plug#end()


function! NetrwOpenMultiTab(current_line,...) range
   " Get the number of lines.
   let n_lines =  a:lastline - a:firstline + 1

   " This is the command to be built up.
   let command = "normal "

   " Iterator.
   let i = 1

   " Virtually iterate over each line and build the command.
   while i < n_lines
      let command .= "tgT:" . ( a:firstline + i ) . "\<CR>:+tabmove\<CR>"
      let i += 1
   endwhile
   let command .= "tgT"

   " Restore the Explore tab position.
   if i != 1
      let command .= ":tabmove -" . ( n_lines - 1 ) . "\<CR>"
   endif

   " Restore the previous cursor line.
   let command .= ":" . a:current_line  . "\<CR>"

   " Check function arguments
   if a:0 > 0
      if a:1 > 0 && a:1 <= n_lines
         " The current tab is for the nth file.
         let command .= ( tabpagenr() + a:1 ) . "gt"
      else
         " The current tab is for the last selected file.
         let command .= (tabpagenr() + n_lines) . "gt"
      endif
   endif
   " The current tab is for the Explore tab by default.

   " Execute the custom command.
   execute command
endfunction

" Define mappings.
augroup NetrwOpenMultiTabGroup
   autocmd!
   autocmd Filetype netrw vnoremap <buffer> <silent> <expr> t ":call NetrwOpenMultiTab(" . line(".") . "," . "v:count)\<CR>"
   autocmd Filetype netrw vnoremap <buffer> <silent> <expr> T ":call NetrwOpenMultiTab(" . line(".") . "," . (( v:count == 0) ? '' : v:count) . ")\<CR>"
augroup END

" Toggle Vexplore with Ctrl-E
function! ToggleVExplorer()
  if exists("t:expl_buf_num")
      let expl_win_num = bufwinnr(t:expl_buf_num)
      if expl_win_num != -1
          let cur_win_nr = winnr()
          exec expl_win_num . 'wincmd w'
          close
          exec cur_win_nr . 'wincmd w'
          unlet t:expl_buf_num
      else
          unlet t:expl_buf_num
      endif
  else
      exec '1wincmd w'
      Vexplore
      let t:expl_buf_num = bufnr("%")
  endif
endfunction

" NeTRW Explorer Settings

let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 15
augroup ProjectDrawer
  autocmd!
  autocmd VimEnter * :Vexplore
augroup END
map <silent> <C-n> :Vexplore<CR>

" Per default, netrw leaves unmodified buffers open. This autocommand
" deletes netrw's buffer once it's hidden (using ':q', for example)
autocmd FileType netrw setl bufhidden=delete
autocmd TabNew * call feedkeys(":Vexplore\<CR>", 'n')

" terminal split below
set splitbelow
autocmd VimEnter * :term bash

ベストアンサー1

代わりに、次の自動コマンドを使用してください。

autocmd VimEnter *
    \ Vexplore |
    \ execute "wincmd l" |
    \ rightbelow term bash

Vimに入ると、シーケンス全体が一度実行されます。複数のコマンドを実行するには、行連続文字(次の行はバックスラッシュで始まります)とバーを使用します。また、autocmdExコマンドが実行されるため、前のコマンドは:実際には必要ありません。

最初のコマンドは、期待どおりに左側にNERDTreeウィンドウを開きます。

次に、wincmd l右側のウィンドウに移動します(参照:help :wincmd)。これは試行に欠けているステップで、次のステップでメインウィンドウの代わりにNERDTreeが分割されます。wincmd内部的に実行する必要がありますexecute。それ以外の場合は、次の内容を解釈しようとし、区切り|文字として機能しません。

最後に、最後のコマンドは端末を開き、明示的rightbelow(参考文献を参照:help :rightbelow)を使用して下部分割を開きます。それだけです!

おすすめ記事