Lightline.vim: Close buffer (X)

Created on 28 Nov 2017  路  6Comments  路  Source: itchyny/lightline.vim

How can I configure the (X) in the upper right to close the current buffer? It doesn't seem to response to anything, except when NERDtree is open I can get the status bar to display NERDTree: cannot close tree root

Thanks in advance!

question

Most helpful comment

Okay, I figured out what's happening. The X closes the current tab, not the current buffer. Try :tabnew and click the X. Unfortunately we cannot configure the action for the closing mark in Vim.

For neovim users; configure as follows to make it close the buffer.

let g:lightline = {
      \ 'component': {
      \   'close': '%@LightlineCloseBuffer@ X %',
      \ },
      \ }

function! LightlineCloseBuffer(...)
  try
    bdelete
  catch
    echohl ErrorMsg
    echom v:exception
    echohl None
  endtry
endfunction

Note that %@ in tabline is neovim only.

All 6 comments

Let me see the result of :set mouse?.

@itchyny mouse=a

Okay, I figured out what's happening. The X closes the current tab, not the current buffer. Try :tabnew and click the X. Unfortunately we cannot configure the action for the closing mark in Vim.

For neovim users; configure as follows to make it close the buffer.

let g:lightline = {
      \ 'component': {
      \   'close': '%@LightlineCloseBuffer@ X %',
      \ },
      \ }

function! LightlineCloseBuffer(...)
  try
    bdelete
  catch
    echohl ErrorMsg
    echom v:exception
    echohl None
  endtry
endfunction

Note that %@ in tabline is neovim only.

@itchyny Thanks, that's getting me closer. Is there a turn-key setup that will have lightline Just Work(tm) with opening files and closing them from the top bar without any of the religious tabs vs buffers vs windows vs .

Thanks again for your help.

Hmm, it's hard to configure as opening files from tabline in Vim. You may try plugins like CtrlP or use GVim.

Thanks for the pointers, and thanks again for all your help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mckellyln picture mckellyln  路  5Comments

ayutheos picture ayutheos  路  4Comments

ghost picture ghost  路  3Comments

Char-Aznable picture Char-Aznable  路  4Comments

yunlingz picture yunlingz  路  4Comments