amarz45
nvim-cmp-buffer-lines
Lua

nvim-cmp completion source for buffer lines

Last updated Mar 10, 2026
70
Stars
1
Forks
4
Issues
0
Stars/day
Attention Score
11
Language breakdown
No language data available.
โ–ธ Files click to expand
README

nvim-cmp Buffer Lines ================

Contents

- packer.nvim - Options - Command-line - Only for certain file types

Preview

Introduction

nvim-cmp Buffer Lines is a completion source for nvim-cmp that provides a source for all the lines in the current buffer. This is especially useful for C programmers. It uses tree-sitter if you have it installed on your system. tree-sitter is optional but recommended.

Installation

packer.nvim

lua
require "packer".startup(function(use)
    use "amarakon/nvim-cmp-buffer-lines"
end)

Setup

lua
require "cmp".setup {
    sources = {
        {
            name = "buffer-lines",
            option = { โ€ฆ }
        }
    }
}

Options

| Option | Type | Default | Description | |:---------------------|:--------|:--------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | words | Boolean | false | Include words | | comments | Boolean | false | Include comments | | line_numbers | Boolean | false | Include line numbers in the completion menu (does not apply on selection/confirmation) | linenumberseparator | String | " " | The separator between the line number and the line text (only used if line_numbers is set. | leading_whitespace | Boolean | true | Include leading whitespace in the completion menu (does not apply on selection/confirmation) | | max_indents | Number | 0 | Maximum indentation level lines can be shown (0-indexed). For example, lines with one or more indents will not be shown when this is set to 1. Set to 0 to show an unlimited amount of indents. | | max_size | Number | 100 | Maximum file size (in kB) for which this plugin will be activated |

Command-line

You can use this source for searching for patterns in the command-line. I recommend using it in conjunction with cmp-buffer for a bread-and-butter combination. The following code block is the configuration I use and recommend.

lua
-- Enable buffer and buffer-lines for / and ? in the command-line
require "cmp".setup.cmdline({ "/", "?" }, {
    mapping = require "cmp".mapping.preset.cmdline(),
    sources = {
        {
            name = "buffer",
            option = { keyword_pattern = [[\k\+]] }
        },
        { name = "buffer-lines" }
    }
})

Only for certain file types

lua
-- Only enable buffer-lines for C and C++
require "cmp".setup.filetype({ "c", "cpp" }, {
    sources = {
        { name = "buffer-lines" }
    }
})

TODO

  • [x] Automatically update the source
  • [x] Cut comments from lines
- [x] Test it to prove it works in all use cases - [x] Find a more efficient implementation with tree-sitter or LSP (Language Server Protocol)
  • [x] Omit duplicate lines
  • [x] Add an option to show line numbers
  • [x] Show indentation level in the completion menu, but not when
selecting or confirming
  • [x] Add an option to choose the maximum indentation level lines will
be shown
  • [ ] Make the plugin more efficient for editing large files
  • [x] Add an option to set a file size limit
  • [x] Add configuration options
  • [ ] Add syntax highlighting
  • [x] Use the current buffer instead of buffer 0
- [ ] Add an option to use all buffers
๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท amarz45/nvim-cmp-buffer-lines ยท Updated daily from GitHub