Vexplore 및 터미널을 사용하여 Vim 자동 시작

Vexplore 및 터미널을 사용하여 Vim 자동 시작

나는 대부분의 경우 전통적인 ide처럼 작동하도록 vim을 설정하고 싶습니다. 내가 하고 싶은 것은 vim 명령을 입력하면 다음과 같이 열리는 것입니다:

빔 창

문제는 다음과 같이 열리는 것입니다.

vim 데모

터미널을 자동으로 시작하고 싶지만 이전 창에서 실행하고 싶습니다. 문서를 읽으려고 노력했지만 문서를 읽고 코드에 넣는 방법에 대한 정보를 얻지 못했습니다. vimrc에 있는 대부분의 코드는 복사하여 붙여넣었고 일부 기본 사항은 이미 알고 있습니다. 첫 번째 사진처럼 자동으로 시작되게 하고 싶습니다.

또한 vim에서 가능한지 확실하지 않은 질문이 하나 더 있습니다. 때로는 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에 들어가면 전체 시퀀스가 ​​한 번 실행됩니다. 여러 명령을 실행하기 위해 줄 연속(백슬래시로 시작하는 후속 줄)과 막대를 사용하고 있습니다. 또한 autocmdEx 명령을 실행하므로 이전 명령이 :실제로 필요하지 않습니다.

첫 번째 명령은 예상대로 왼쪽에 NERDTree 창을 엽니다.

둘째, wincmd l오른쪽 창으로 이동합니다( 참조 :help :wincmd). 이는 시도에서 누락된 단계로, 다음 단계에서 기본 창 대신 NERDTree를 분할하게 됩니다. 는 wincmd내부에서 실행되어야 합니다 . 그렇지 않으면 뒤에 오는 를 execute해석하려고 시도하여 구분 기호로 작동하지 않게 되기 때문입니다.|

마지막으로 마지막 명령은 맨 아래에 있는 분할을 열려면 명시적 rightbelow(참조 ) 을 사용하여 터미널을 엽니다 . :help :rightbelow그게 다야!

관련 정보