
私は、vim をほとんどの部分で従来の IDE のように動作するように設定したいと考えています。私がやりたいのは、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 を使用してください:
autocmd VimEnter *
\ Vexplore |
\ execute "wincmd l" |
\ rightbelow term bash
これは、Vim に入ると、シーケンス全体を 1 回実行します。行継続 (後続の行はバックスラッシュで始まります) とバーを使用して、複数のコマンドを実行します。また、はautocmd
Ex コマンドを実行するため、コマンドの前に を:
付ける必要はまったくないことに注意してください。
最初のコマンドは、予想どおり、左側に NERDTree ウィンドウを開きます。
次に、wincmd l
は右側のウィンドウに移動します ( を参照:help :wincmd
)。これが試行で欠落しているステップであり、次のステップでメイン ウィンドウではなく NERDTree が分割される原因となっています。wincmd
は 内で実行する必要がありますexecute
。そうしないと、 は に続く を解釈しようとし|
、区切りとして機能しなくなります。
rightbelow
最後に、最後のコマンドは、明示的な( を参照:help :rightbelow
) を使用して、下部のこの分割をターミナルで開きます。これで完了です。