romgrk / barbar.nvim

The neovim tabline plugin.
2.3k stars 85 forks source link

Cannot navigate away from a modified/unsaved buffer #153

Closed SethGunnells closed 3 years ago

SethGunnells commented 3 years ago

Description

A thousand pardons if it's obvious that this is not possible. I'm not new to nvim but I don't have a very deep understanding of all its workings. (Using this plugin has greatly increased my understanding of buffers, windows, tabs, etc!) I'm coming from using tabs for everything. Opening with tabe, closing with tabc and so on.

Whenever I try to navigate away from a buffer that I have not saved using BufferNext or BufferPrevious I get this error:

Error detected while processing function <SNR>28_goto_buffer_relative:
line    1:
E5108: Error executing lua ...ite/pack/paqs/start/barbar.nvim/lua/bufferline/state.lua:364: Vim(buffer):E37: No write since last change (add ! to override)
Press ENTER or type command to continue

Is there something I can do to make this possible? I'm also willing to open a PR to help if I can be directed towards what I'd need to change.

To Reproduce

  1. Open more than one buffer
  2. Modify the contents of one
  3. Try to navigate away from it using BufferNext or BufferPrevious

init.lua:

-- https://github.com/nanotee/nvim-lua-guide

local map = vim.api.nvim_set_keymap
local g = vim.g
local o = vim.o
local api = vim.api

-- map the leader key
map('n', '<Space>', '', { noremap = true })
g.mapleader = ' '

-- use 'jk' to stop editing
map('i', 'jk', '<Escape>', { noremap = true })

o.completeopt = 'menuone,noselect'
o.expandtab = true
o.exrc = true
o.number = true
o.scrolloff = 1
o.secure = true
o.shiftwidth = 2
o.sidescrolloff = 5
o.smarttab = true
o.softtabstop = 0
o.tabstop = 8
o.termguicolors = true

-------------
-- PLUGINS --
-------------

require 'paq-nvim' {
  -- package manager
  'savq/paq-nvim';
  -- fancy icons for nvim
  'kyazdani42/nvim-web-devicons';
  -- fancy status line
  'hoob3rt/lualine.nvim';
  -- nord theme with TreeSitter support
  'shaunsingh/nord.nvim';
  -- add easy LSP configs
  'neovim/nvim-lspconfig';
  -- add autocomplete
  'hrsh7th/nvim-compe';
  -- allow plugins to use the . command
  'tpope/vim-repeat';
  -- TreeSitter manager
  'nvim-treesitter/nvim-treesitter';
  -- create pairs for sensible characters automatically
  'jiangmiao/auto-pairs';
  -- quickly jump around
  'ggandor/lightspeed.nvim';
  -- easily change surrounding characters
  'tpope/vim-surround';
  -- fancy tabbar
  'romgrk/barbar.nvim';
  -- file tree
  'kyazdani42/nvim-tree.lua';
  -- telescope
  'nvim-lua/popup.nvim';
  'nvim-lua/plenary.nvim';
  'nvim-telescope/telescope.nvim';
  -- git sidebar and manipulating changes
  'airblade/vim-gitgutter';
  -- easy comment manipulation
  'tpope/vim-commentary';
}

require'nord'.set()
local colors = require'nord/colors'

require'lualine'.setup {
  options = {
    theme = 'nord'
  },
  sections = {
    lualine_x = {'encoding', 'filetype', {'diagnostics', sources = {'nvim_lsp'}}},
    lualine_y = {}
  }
}

require'nvim-treesitter.configs'.setup {
  ensure_installed = 'maintained',
  highlight = {
    enable = true
  },
  incremental_selection = {
    enable = true
  },
  indent = {
    enable = true
  }
}

-- go here for more LSPs: https://github.com/neovim/nvim-lspconfig

local lspconfig = require'lspconfig'
local util = lspconfig.util

lspconfig.tsserver.setup{
  on_attach = function(client)
    client.resolved_capabilities.document_formatting = false
  end;
}

lspconfig.diagnosticls.setup{
  filetypes = {"javascript", "typescript"},
  root_dir = function(fname)
    return util.root_pattern("tsconfig.json")(fname) or
    util.root_pattern(".eslintrc.js")(fname);
  end,
  init_options = {
    linters = {
      eslint = {
        command = "eslint_d",
        rootPatterns = {".eslintrc.js", ".git"},
        debounce = 100,
        args = {
          "--stdin",
          "--stdin-filename",
          "%filepath",
          "--format",
          "json"
        },
        sourceName = "eslint",
        parseJson = {
          errorsRoot = "[0].messages",
          line = "line",
          column = "column",
          endLine = "endLine",
          endColumn = "endColumn",
          message = "[eslint] ${message} [${ruleId}]",
          security = "severity"
        },
        securities = {
          [2] = "error",
          [1] = "warning"
        }
      },
    },
    formatters = {
      prettier = {
        command = "prettier",
        args = {"%filepath"}
      }
    },
    filetypes = {
      javascript = "eslint",
      typescript = "eslint"
    },
    formatFiletypes = {
      javascript = 'prettier'
    }
  }
}

vim.fn.sign_define('LspDiagnosticsSignError', { text='' })
vim.fn.sign_define('LspDiagnosticsSignWarning', { text='' })
vim.fn.sign_define('LspDiagnosticsSignInformation', { text='' })
vim.fn.sign_define('LspDiagnosticsSignHint', { text='' })

map('n', '<leader>D', '<cmd>lua vim.lsp.buf.declaration()<CR>', { noremap = true, silent = true })
map('n', '<leader>E', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', { noremap = true, silent = true })
map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', { noremap = true, silent = true })
map('n', '<leader>F', '<cmd>lua vim.lsp.buf.formatting()<CR>', { noremap = true, silent = true })
map('n', '<leader>R', '<cmd>lua vim.lsp.buf.rename()<CR>', { noremap = true, silent = true })

api.nvim_command([[command FormatEnable augroup sethfmt | exe "au!" | exe "au BufWrite * lua vim.lsp.buf.formatting_sync()" | augroup END]])
api.nvim_command([[command FormatDisable au! sethfmt]])
api.nvim_command([[FormatEnable]])

require'compe'.setup {
  source = {
    buffer = true;
    nvim_lsp = true;
  }
}

g.nvim_tree_auto_open = 1
map('n', '<leader>t', ':NvimTreeToggle<CR>', { noremap = true })

map('n', '<leader>,', ':BufferPrevious<CR>', { noremap = true, silent = true })
map('n', '<leader>.', ':BufferNext<CR>', { noremap = true, silent = true })
map('n', '<leader><', ':BufferMovePrevious<CR>', { noremap = true, silent = true })
map('n', '<leader>>', ':BufferMoveNext<CR>', { noremap = true, silent = true })
map('n', '<leader>c', ':BufferClose<CR>', { noremap = true, silent = true })
map('n', '<leader>s', ':BufferPick<CR>', { noremap = true, silent = true })
map('n', '<leader>bd', ':BufferOrderByDirectory<CR>', { noremap = true, silent = true })
map('n', '<leader>bl', ':BufferOrderByLanguage<CR>', { noremap = true, silent = true })

telescope = require'telescope.builtin'
map('n', '<leader>f', '<cmd>lua telescope.find_files()<CR>', { noremap = true, silent = true })
map('n', '<leader>g', '<cmd>lua telescope.grep_string()<CR>', { noremap = true, silent = true })
map('n', '<leader>G', '<cmd>lua telescope.live_grep()<CR>', { noremap = true, silent = true })
map('n', '<leader><leader>b', '<cmd>lua telescope.buffers()<CR>', { noremap = true, silent = true })
map('n', '<leader>r', '<cmd>lua telescope.lsp_references()<CR>', { noremap = true, silent = true })
map('n', '<leader>d', '<cmd>lua telescope.lsp_definitions()<CR>', { noremap = true, silent = true })
map('n', '<leader><leader>s', '<cmd>lua telescope.lsp_document_symbols()<CR>', { noremap = true, silent = true })
map('n', '<leader>a', '<cmd>lua telescope.lsp_code_actions()<CR>', { noremap = true, silent = true })
map('x', '<leader>a', '<cmd>lua telescope.lsp_range_code_actions()<CR>', { noremap = true, silent = true })
map('n', '<leader>e', '<cmd>lua telescope.lsp_document_diagnostics()<CR>', { noremap = true, silent = true })
map('n', '<leader>i', '<cmd>lua telescope.lsp_implementations()<CR>', { noremap = true, silent = true })
map('n', '<leader><leader>t', '<cmd>lua telescope.treesitter()<CR>', { noremap = true, silent = true })
map('n', '<leader><leader>B', '<cmd>lua telescope.builtin()<CR>', { noremap = true, silent = true })

Informations Neovim version: v0.5.0-dev+1455-gf83c25942

SethGunnells commented 3 years ago

For anyone who finds this later, turn on the hidden option in your init.vim/init.lua file.