Je veux commencer à utiliser Vim comme éditeur principal, car j'ai entendu dire que c'était vraiment génial et productif. J'ai donc installé un tas de plugins en utilisant Pathogen, et j'ai créé un joli fichier long .vimrc
. un des plug-ins que j'utilise (et vraiment) est NERDTree
, donc je copier les lignes suivantes dans mon fichier .vimrc
à partir du dépôt git NERDTree:Vim créer un tampon vide au lieu de quitter
autocmd StdinReadPre * let s:std_in = 1
autocmd VimEnter *
\ NERDTree |
\ wincmd p
autocmd VimEnter *
\ if argc() == 0 && !exists("s:std_in") |
\ NERDTree |
\ wincmd p |
\ endif
autocmd VimEnter *
\ if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") |
\ exe 'NERDTree' argv()[0] |
\ wincmd p |
\ ene |
\ endif
autocmd BufEnter *
\ if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) |
\ q |
\ endif
maintenant à ma question: je veux faire donc pas quoi qu'il arrive, vim ne quittera pas à moins que je explicitement dire à (en utilisant une commande spéciale comme :Quit
ou en utilisant ⌘q sur MacVim). Donc, fondamentalement, si je n'ai, par exemple, qu'un tampon contenant un fichier ouvert avec un tampon NERDTree (ou même si j'ai juste un seul tampon ouvert, pas de NERDTree), quand je :q
ou :close
ce tampon, je veux qu'il présente moi avec un tampon vide, comme quand vous venez d'ouvrir vim. Mais je ne suis pas sûr de savoir comment écrire cela, donc je voudrais de l'aide sur ce qu'il faut ajouter à mon .vimrc
TL; DR: Comment faire pour que Vim sorte seulement en utilisant une commande explicite, et pas quand vous quittez le dernier tampon?
(EDIT: Lire les commentaires à @ la réponse de romainl pour plus de précisions sur ce qu'est exactement je cherche
PS Voici mon fichier complet .vimrc
, juste au cas où:.
" => Pathogen and FTPlugins Setup
execute pathogen#infect()
filetype plugin indent on
let mapleader = "\ "
" => Color Theme Options
colorscheme monokai
" => Custom Commands
""""command W w
""""command Q q
""""command Wq wq
""""command WQ wq
""""command B b
command Tabs set listchars=tab:\|\ ,trail:~,extends:>,precedes:<
command NoTabs set listchars=tab:\ \ ,trail:~,extends:>,precedes:<
" =*=> Plugin-Related
" =*=> Theme-Related
command Light
\ set background=light |
\ colorscheme solarized
command Dark
\ set background=dark |
\ colorscheme solarized
" => Custom Mappings
" =*=> Basic Editor Commands
nnoremap ' :%s/
" Find and replace
nnoremap ! :!
" Run shell command
nnoremap <C-o> :bprevious<CR>
nnoremap <C-p> :bnext<CR>
nnoremap <leader> <C-w>
" =*=> Workdir Manipulation
" nnoremap <C-j> :lcd %:p:h<CR>
" =*=> Plugin-Related
" =*=*=> NERDTree
noremap <C-f> :NERDTreeToggle<CR>
noremap <C-d> :NERDTreeFind<CR>
" =*=*=> BufExplorer
nnoremap <Tab> :BufExplorerHorizontalSplit<CR>
" => Settings
syntax on " Enable syntax highlighting
set number " Show line numbers
set ruler " Show row & column number
set splitright " Vertically split to the right by default
set splitbelow " Horizontally split below by default
set ignorecase " Case-insesitive tab completion
set hidden " Allow buffer switching with unwritten changes
set laststatus=2 " Always show status bar (even when there's only one window)
set wildchar=<Tab> wildmenu wildmode=full " Enhanced tab-completion
set listchars=tab:\|\ ,trail:~,extends:>,precedes:< " Set symbols for hidden characters
set list " Show hidden characters
set autochdir " When opening a file, automatically set workingdir (of the current buffer) to the directory containing that file
set nowrap " Disable line wrapping
" =*=> Tab Settings (commonly overwritten in ftplugins)
set tabstop=4
set shiftwidth=4
set shiftround
set autoindent
set smartindent
set expandtab " Output spaces when pressing <Tab>, not actual tab characters ('\t')
" =*=> Split vertically by default
" =*=> GVim Settings
set guioptions-=r " Remove right-hand scroll bar
set guioptions-=L " Remove left-hand scroll bar
" =*=> Plugin-Related
" =*=*=> NERDTree
let NERDTreeShowHidden = 1 " Always show hidden files
let NERDTreeShowBookmarks = 1
" =*=*=> NERDCommenter
let g:NERDSpaceDelims = 1 " Add spaces after comment delimiters by default
let g:NERDCommentEmptyLines = 1 " Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDTrimTrailingWhitespace = 1 " Enable trimming of trailing whitespace when uncommenting
" => AutoCommands
autocmd BufEnter * lcd %:p:h " When opening a file, automatically set workingdir (of the current buffer) to the directory containing that file
" =*=>Plugin-Related
" =*=*=> NERDTree
autocmd StdinReadPre * let s:std_in = 1
autocmd VimEnter *
\ NERDTree |
\ wincmd p
autocmd VimEnter *
\ if argc() == 0 && !exists("s:std_in") |
\ NERDTree |
\ wincmd p |
\ endif
autocmd VimEnter *
\ if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") |
\ exe 'NERDTree' argv()[0] |
\ wincmd p |
\ ene |
\ endif
autocmd BufEnter *
\ if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) |
\ q |
\ endif
" Up to here, copied from repository's README.md
" => Miscellanea
highlight NonText guifg=DimGray ctermbg=NONE guibg=NONE
highlight SpecialKey guifg=DimGray ctermbg=NONE guibg=NONE " Set Hidden Characters Color
Quel serait l'avantage de cela? Si vous voulez un buffer vide, faites juste ': enew'. – romainl
Je sais, mais mon problème est que chaque fois que je veux fermer un fichier (parce que j'ai fini de l'éditer), je ': q' ou': close' il. Mais la plupart du temps, c'est complètement tout à fait Vim. Je veux un comportement similaire à la plupart des éditeurs, où il va juste ouvrir un fichier vide – Hexa
': q' est pour les fenêtres, pas de tampons. – romainl