Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Debugging in NeoVim the print() way!

License

NotificationsYou must be signed in to change notification settings

andrewferrier/debugprint.nvim

Repository files navigation

▗▄▄▄ ▗▄▄▄▖▗▄▄▖ ▗▖ ▗▖ ▗▄▄▖▗▄▄▖ ▗▄▄▖ ▗▄▄▄▖▗▖  ▗▖▗▄▄▄▖▐▌  █▐▌   ▐▌ ▐▌▐▌ ▐▌▐▌   ▐▌ ▐▌▐▌ ▐▌  █  ▐▛▚▖▐▌  █▐▌  █▐▛▀▀▘▐▛▀▚▖▐▌ ▐▌▐▌▝▜▌▐▛▀▘ ▐▛▀▚▖  █  ▐▌ ▝▜▌  █▐▙▄▄▀▐▙▄▄▖▐▙▄▞▘▝▚▄▞▘▝▚▄▞▘▐▌   ▐▌ ▐▌▗▄█▄▖▐▌  ▐▌  █

Test statusGitHub Licensedebugprint dotfyle shield

Overview

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.

Features

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).

Demo

Recent interview video showing most of the key features of debugprint:

Recent interview video showing most of the key features of debugprint

Older, shorter demo video showing basic features. 

Installation

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.

Keymappings and Commands

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.

ModeDefault Key / CmdPurposeAbove/Below Line
Normalg?pPlain debugBelow
Normalg?PPlain debugAbove
Normalg?vVariable debugBelow
Normalg?VVariable debugAbove
NormalNoneVariable debug (always prompt for variable)Below
NormalNoneVariable debug (always prompt for variable)Above
Normalg?spPlain debugAbove and below (surround)
Normalg?svVariable debugAbove and below (surround)
NormalNoneVariable debug (always prompt for variable)Above and below (surround)
NormalNoneDelete debug lines in buffer-
NormalNoneComment/uncomment debug lines in buffer-
InsertCtrl-G pPlain debugIn-place
InsertCtrl-G vVariable debug (always prompt for variable)In-place
Visualg?vVariable debugBelow
Visualg?VVariable debugAbove
Op-pendingg?oVariable debugBelow
Op-pendingg?OVariable debugAbove
Op-pendingg?soVariable debugAbove and below (surround)
Command:Debugprint deleteDelete all debug print statements in the current buffer-
Command:Debugprint commenttoggleComment/uncomment all debug print statements in the current buffer-
Command:Debugprint resetcounterReset debug print persistent counter (only for built-in counter implementation)-
Command:Debugprint searchSearch for all debug print lines in the current directory usingfzf-lua,telescope.nvim orsnacks.nvim-
Command:Debugprint qflistSearch 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.

Mapping Deprecation

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.

Other Options

debugprint supports the following options in its globalopts object:

OptionDefaultPurpose
move_to_debuglinefalseWhen adding a debug line, moves the cursor to that line
display_locationtrueInclude the filename and linenumber of the line being debugged in the debug message
display_countertrueInclude 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_snippettrueInclude a snippet of the line above/below in the debug message (plain debug lines only) for context
notify_for_registerstrueIf set to false, disables the notifications that occur when debugprint lines are inserted or appended to registers
highlight_linesFunction 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
filetypesSee (the code)Custom filetypes - seeshowcase
print_tagDEBUGPRINTThe 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
pickernilOverride the picker used for the:Debugprint search command. Valid values:fzf-lua,telescope, orsnacks.picker. Ifnil, this is auto-selected based on availability.

Known Limitations

  • debugprint does 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 delete or similar, don't format yourfile between inserting them and running this command. Seethisissue fordiscussion on this.

Feature Comparison with Similar Plugins

(This table is quite wide, you may need to scroll horizontally)

Featuredebugprint.nvimtimber.nvimnvim-chainsawprinter.nvimrefactoring.nvimvim-printerlogsitter
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 inLuaLuaLuaLuaLuaVimLLua

There is alsoa similar table in the nvim-chainsaw documentation.

Other similar plugins (less popular or unmaintained):


[8]ページ先頭

©2009-2025 Movatter.jp