- Notifications
You must be signed in to change notification settings - Fork26
Debugging in NeoVim the print() way!
License
andrewferrier/debugprint.nvim
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
▗▄▄▄ ▗▄▄▄▖▗▄▄▖ ▗▖ ▗▖ ▗▄▄▖▗▄▄▖ ▗▄▄▖ ▗▄▄▄▖▗▖ ▗▖▗▄▄▄▖▐▌ █▐▌ ▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌ ▐▌▐▌ ▐▌ █ ▐▛▚▖▐▌ █▐▌ █▐▛▀▀▘▐▛▀▚▖▐▌ ▐▌▐▌▝▜▌▐▛▀▘ ▐▛▀▚▖ █ ▐▌ ▝▜▌ █▐▙▄▄▀▐▙▄▄▖▐▙▄▞▘▝▚▄▞▘▝▚▄▞▘▐▌ ▐▌ ▐▌▗▄█▄▖▐▌ ▐▌ █debugprint is a NeoVim plugin that simplifies debuggingfor those who prefer a low-tech approach.Instead of using a sophisticated debugger likenvim-dap, some people prefer using a'print'-like statement to trace the output during execution. Withdebugprint,you can insert these statements, including the values of variables, relevant tothe language you're editing.
debugprint is inspired byvim-debugstring; updated forthe NeoVim generation. It:
Supports 40 filetypes/programming languages out-of-the-box, includingPython, JavaScript/TypeScript, Java, C/C++ andmore.It can also be extended tosupport other languages or customize existing ones.
Includes reference information in each 'print line' such as file names, linenumbers, a counter (which persists between NeoVim sessions), and snippets ofother lines to make it easier to cross-reference them in output. Each of thesecan be optionally disabledglobally oron a per-filetypebasis.
Will highlight inserted lines to make them easier to find in your code(depends onmini.nvimormini.hipatterns).
Can output the value of variables (or simple expressions) - it will detect avariable name under the cursor for some languages using Treesitter, or willprompt with a sensible default. It understands Treesitter embedded languages(e.g. JavaScript-in-HTML).
Provideskeymappings for normal, insert,visual, and operator-pending modes. Supportsdot-repeat.Can insert two 'surrounding' lines at the same time.
Supports direct writing to NeoVim registers for batch insert of debugprintlines.
Providescommands to delete or comment debugginglines added to the current buffer, search for those lines in the currentdirectory (project) usingfzf-lua,telescope.nvim orsnacks.nvim, and add those lines tothe quickfix list.
Can optionally move to the inserted line (or not).
Recent interview video showing most of the key features of debugprint:

Older, shorter demo video showing basic features.
Requires NeoVim 0.10+.
Example forlazy.nvim:
return {"andrewferrier/debugprint.nvim",-- opts = { … },dependencies= {"echasnovski/mini.nvim",-- Optional: Needed for line highlighting (full mini.nvim plugin)-- ... or ..."echasnovski/mini.hipatterns",-- Optional: Needed for line highlighting ('fine-grained' hipatterns plugin)"ibhagwan/fzf-lua",-- Optional: If you want to use the `:Debugprint search` command with fzf-lua"nvim-telescope/telescope.nvim",-- Optional: If you want to use the `:Debugprint search` command with telescope.nvim"folke/snacks.nvim",-- Optional: If you want to use the `:Debugprint search` command with snacks.nvim },lazy=false,-- Required to make line highlighting work before debugprint is first usedversion="*",-- Remove if you DON'T want to use the stable version}
(Examples for other package managershere.)
The sections below detail the allowed options that can appear in theoptsobject. There is also a showcase of example and advanced debugprintconfigurationshere which can be dropped into your configurationfiles to further enhance your use of debugprint.
Please subscribe tothis GitHubissue to benotified of any breaking changes todebugprint.
By default, the plugin will create some keymappings and commands for use 'out ofthe box'. There is also some functionality which is not mapped to anykeymappings by default, but could be. This is all shown in the following table.
| Mode | Default Key / Cmd | Purpose | Above/Below Line |
|---|---|---|---|
| Normal | g?p | Plain debug | Below |
| Normal | g?P | Plain debug | Above |
| Normal | g?v | Variable debug | Below |
| Normal | g?V | Variable debug | Above |
| Normal | None | Variable debug (always prompt for variable) | Below |
| Normal | None | Variable debug (always prompt for variable) | Above |
| Normal | g?sp | Plain debug | Above and below (surround) |
| Normal | g?sv | Variable debug | Above and below (surround) |
| Normal | None | Variable debug (always prompt for variable) | Above and below (surround) |
| Normal | None | Delete debug lines in buffer | - |
| Normal | None | Comment/uncomment debug lines in buffer | - |
| Insert | Ctrl-G p | Plain debug | In-place |
| Insert | Ctrl-G v | Variable debug (always prompt for variable) | In-place |
| Visual | g?v | Variable debug | Below |
| Visual | g?V | Variable debug | Above |
| Op-pending | g?o | Variable debug | Below |
| Op-pending | g?O | Variable debug | Above |
| Op-pending | g?so | Variable debug | Above and below (surround) |
| Command | :Debugprint delete | Delete all debug print statements in the current buffer | - |
| Command | :Debugprint commenttoggle | Comment/uncomment all debug print statements in the current buffer | - |
| Command | :Debugprint resetcounter | Reset debug print persistent counter (only for built-in counter implementation) | - |
| Command | :Debugprint search | Search for all debug print lines in the current directory usingfzf-lua,telescope.nvim orsnacks.nvim | - |
| Command | :Debugprint qflist | Search for all debug print lines in the current directory and populate quickfix list | - |
Each of the keymappings (except for 'surround' keys and insert modes) can alsobe prefixed with a register, see theshowcase foran example of how to use this to insert debugprint lines in batches.
The keys outlined above can be specifically overridden using thekeymaps objectinside theopts object used above during configuration of debugprint. For example,if configuring vialazy.nvim, it might look like this:
return {"andrewferrier/debugprint.nvim",opts= {keymaps= {normal= {plain_below="g?p",plain_above="g?P",variable_below="g?v",variable_above="g?V",variable_below_alwaysprompt="",variable_above_alwaysprompt="",surround_plain="g?sp",surround_variable="g?sv",surround_variable_alwaysprompt="",textobj_below="g?o",textobj_above="g?O",textobj_surround="g?so",toggle_comment_debug_prints="",delete_debug_prints="", },insert= {plain="<C-G>p",variable="<C-G>v", },visual= {variable_below="g?v",variable_above="g?V", }, },-- … Other options },}
You only need to include the keys which you wish to override, others will defaultas shown above. Setting any key to"" orfalse will skip it.
The default keymappings are chosen specifically because ordinarily in NeoVimthey are used to convert sections to ROT-13, which most folks don't use.
Note: As of recent versions of debugprint, the command names should no longer becustomized, but instead theDebugprint top-level command with subcommandsshould be used.
Warning
Note: as of version 2.0.0, the old mechanism of configuring keymaps/commandswhich specifically allowed for mapping directly torequire('debugprint').debugprint(...) is no longer officially supported ordocumented. This is primarily because ofconfusion which arose over how to dothis mapping. Existing mappings performed this way are likely to continue towork for some time. You should, however, migrate over to the new method outlinedabove. If this doesn't give you the flexibility to map how you wish for somereason, please open anissue.
debugprint supports the following options in its globalopts object:
| Option | Default | Purpose |
|---|---|---|
move_to_debugline | false | When adding a debug line, moves the cursor to that line |
display_location | true | Include the filename and linenumber of the line being debugged in the debug message |
display_counter | true | Include the increasing integer counter in the debug message. (If you want to customize this counter, or make it non-persistent, see instructions in theshowcase for an example). |
display_snippet | true | Include a snippet of the line above/below in the debug message (plain debug lines only) for context |
notify_for_registers | true | If set to false, disables the notifications that occur when debugprint lines are inserted or appended to registers |
highlight_lines | Function which checks for large buffers (seethe code) | Apply highlighting to debugprint lines. Can be set totrue,false, or a function that returns a boolean. Seeshowcase for more information on customization and limitations |
filetypes | See (the code) | Custom filetypes - seeshowcase |
print_tag | DEBUGPRINT | The string inserted into each print statement, which can be used to uniquely identify statements inserted bydebugprint. If you set this to'' (the empty string), no print tag will be included, but this will disable the ability to delete, comment, or highlight print statements viadebugprint |
picker | nil | Override the picker used for the:Debugprint search command. Valid values:fzf-lua,telescope, orsnacks.picker. Ifnil, this is auto-selected based on availability. |
debugprintdoes not handle deleting reformatted debug lines where aformatter has split them across multiple lines. If you want to be able to easilydelete your debug lines usingDebugprint deleteor similar, don't format yourfile between inserting them and running this command. Seethisissue fordiscussion on this.
(This table is quite wide, you may need to scroll horizontally)
| Feature | debugprint.nvim | timber.nvim | nvim-chainsaw | printer.nvim | refactoring.nvim | vim-printer | logsitter |
|---|---|---|---|---|---|---|---|
| Include line numbers in log lines | 👍 | 👍 (via user config) | 👍 (via user config) | 👍 | 👍 | ❌ | 👍 |
| Include other location information in log lines | 👍 | ❌ | 👍 (via user config) | 👍 | 👍 | ❌ | 👍 |
| Language-derived location (for some filetypes) to resist line movement | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Persistent location counter between NeoVim sessions | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Print plain debug lines | 👍 | 👍 (via user config) | 👍 | ❌ | 👍 | ❌ | ❌ |
| Print variables using treesitter | 👍 | 👍 | 👍 | ❌ | 👍 | ❌ | ❌ |
| 'Surround' lines with debugging above and below | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Use treesitter to locate log targets | (some languages) | 👍 | 👍 | ❌ | ❌ | ❌ | ❌ |
| Use treesitter to intelligently insert log lines | ❌ | 👍 | 👍 | ❌ | ❌ | ❌ | ❌ |
| Enter variables/expressions using prompts | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Fallback to variables using current word/heuristic | 👍 | ❌ | 👍 | ❌ | ❌ | 👍 | ❌ |
| Print variables using motions/operator | 👍 | 👍 | ❌ | 👍 | ❌ | ❌ | ❌ |
| Add plain or variable debug lines in insert mode | 👍 | ❌ | ❌ | ❌: | ❌ | ❌ | ❌ |
| Add variable debug lines in visual mode | 👍 | 👍 | 👍 | 👍 | 👍 | 👍 | ❌ |
| Print assertions | ❌ | 👍 (via user config) | 👍 | ❌ | ❌ | ❌ | ❌ |
| Print stack traces | ❌ | 👍 (via user config) | 👍 | ❌ | ❌ | ❌ | ❌ |
| Add time-tracking logic | ❌ | 👍 (via user config) | 👍 | ❌ | ❌ | ❌ | ❌ |
| Add debugging breakpoints | ❌ | 👍 (via user config) | 👍 | ❌ | ❌ | ❌ | ❌ |
| Print debug lines above/below current line | 👍 | 👍 | ❌ | (via global config) | ❌ | 👍 | ❌ |
| Supportsdot-repeat | 👍 | 👍 | 👍 | ❌ | ❌ | ❌ | ❌ |
| Can control whether to move to inserted lines | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Clean up/delete all debug lines in buffer | 👍 | 👍 | 👍 | ❌ | ❌ | ❌ | ❌ |
| Comment/uncomment all debug lines in buffer | 👍 | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ |
| Comment/uncomment all debug lines in selected range | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Can put debugprint text into register | 👍 | ❌ | ❌ | 👍 | ❌ | ❌ | ❌ |
| Search for debugprint lines usingfzf-lua,telescope.nvim orsnacks.nvim | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Search for debugprint lines and populate quickfix list | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Extra visual emphasis of log statements | 👍 Highlights inserted lines | 👍 Flashes to highlight lines on insertion | 👍 status line counter, signcolumn, line-highlight, scrollbar | ❌ | ❌ | ❌ | ❌ |
| Can insert logs in batches | 👍 (using registers) | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ |
| Log watcher mechanism | ❌ | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ |
| Dynamic filetype configuration/log templates | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Completely customizable log templates | ❌ | 👍 | 👍 | 👍 | ❌ | ❌ | ❌ |
| Built-in support for: | - | - | - | - | - | - | - |
| Apex (Salesforce) | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| AppleScript | 👍 | ❌ | 👍 | ❌ | ❌ | ❌ | ❌ |
| Astro | 👍 | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ |
| bash/sh | 👍 | ❌ | 👍 | 👍 | ❌ | 👍 | ❌ |
| C | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| C# (C Sharp) | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| C++ | 👍 | ❌ | ❌ | 👍 | 👍 | 👍 | ❌ |
| CMake | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Cobol | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Crystal | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| dart | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Docker | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| DOS/Windows Batch | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Elixir | 👍 | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ |
| fish | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Fortran | 👍 | ❌ | ❌ | ❌ | ❌ | 👍 | ❌ |
| GDScript | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Golang | 👍 | 👍 | 👍 | 👍 | 👍 | 👍 | 👍 |
| Haskell | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Java | 👍 | ❌ | ❌ | 👍 | 👍 | 👍 | ❌ |
| Javascript/Typescript | 👍 | 👍 | 👍 | 👍 | 👍 | 👍 | 👍 |
| Kotlin | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| lean | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Lisp | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| lua | 👍 | 👍 | 👍 | 👍 | 👍 | 👍 | 👍 |
| luau | 👍 | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ |
| GNU Make | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Nim | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Odin | ❌ | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ |
| Perl | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| PHP | 👍 | ❌ | ❌ | ❌ | 👍 | ❌ | ❌ |
| Powershell/ps1 | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Python | 👍 | ❌ | 👍 | 👍 | 👍 | 👍 | ❌ |
| R | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| React | 👍 | ❌ | 👍 | ❌ | ❌ | ❌ | ❌ |
| Ruby | 👍 | 👍 | 👍 | ❌ | 👍 | ❌ | ❌ |
| Rust | 👍 | 👍 | 👍 | 👍 | ❌ | 👍 | ❌ |
| Svelte | 👍 | ❌ | 👍 | ❌ | ❌ | ❌ | ❌ |
| Swift | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| tcl | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| VimL (vimscript) | 👍 | ❌ | ❌ | 👍 | ❌ | 👍 | ❌ |
| Vue | 👍 | ❌ | 👍 | ❌ | ❌ | ❌ | ❌ |
| Zig | 👍 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| zsh | 👍 | ❌ | 👍 | 👍 | ❌ | 👍 | ❌ |
| Add custom filetypes | 👍 | 👍 | 👍 | 👍 | ❌ | ❌ | 👍 |
| Implemented in | Lua | Lua | Lua | Lua | Lua | VimL | Lua |
There is alsoa similar table in the nvim-chainsaw documentation.
Other similar plugins (less popular or unmaintained):
About
Debugging in NeoVim the print() way!
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.