Debug printf()-style at the speed of light
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
ftplugin
misc
plugin
test
.gitignore
.projections.json
.travis.yml
LICENSE
README.md
addon-info.json

README.md

vim-debugstring

     _      _                     _        _
    | |    | |                   | |      (_)
  __| | ___| |__  _   _  __ _ ___| |_ _ __ _ _ __   __ _
 / _` |/ _ \ '_ \| | | |/ _` / __| __| '__| | '_ \ / _` |
| (_| |  __/ |_) | |_| | (_| \__ \ |_| |  | | | | | (_| |
 \__,_|\___|_.__/ \__,_|\__, |___/\__|_|  |_|_| |_|\__, |
                         __/ |                      __/ |
                        |___/                      |___/

Purpose

debugstring aims to automate standard debugging operations (e.g., segfaults). It does that by facilitating the ubiquitous printf()-debugging i.e., scatter logging statements around the various code snippets that you want to test.

Demos

Standard debugging - C++

demo_gif

Debugging for expression/variables - C++

demo_gif

Features

  • The form and syntax of the logging statements target the language at hand (e.g., use printf() in C/C++ but puts() in Ruby)

Currently the following languages are supported. First column corresponds to the standard debugging string while the second to the case of debugging for a specific variable.

Lang Debug String Debug Variable
Awk
C ✔️ ✔️
C#
C++ ✔️ ✔️
CMake ✔️ ✔️
D
Fortran ✔️ ✔️
Go
Haskell ✔️ ✔️
Java ✔️ ✔️
Javascript ✔️
Julia
Lua
Matlab
PHP ✔️ ✔️
Perl
Python ✔️ ✔️
R ✔️ ✔️
Ruby ✔️ ✔️
Rust ✔️ ✔️
Scala
Shell ✔️ ✔️
Swift
Vim ✔️ ✔️
Visual Basic
  • Support for debugging variable expressions e.g., the values of variables or arbitrary expressions at certain parts of your code
  • Support for vim-repeat. No need for repeat the same mapping, or rewrite the lengthy expression that you want to monitor, just use the . character

For a more detailed outline of debugstring check doc/debugstring.txt

Usage

Use the mappings of your choice to place unique logging directives during debugging times.

nnoremap <your-key-combination> <Plug>DumpDebugString
nnoremap <a-second-key-combination> <Plug>DumpDebugStringExpr

Default mappings are: <Leader>ds, <Leader>dS respectively.

An example of using it in a C++ file is given below:

// Debug String
std::cout << "[a.c:4] DEBUGGING STRING ==> " << 0 << std::endl;

// Debug Variable
std::cout << "[a.c:4] a_variable: " << a_variable << std::endl;

Remarks - Debugging

  • Make sure that filetype plugin is enabled. A line like filetype plugin on in your .vimrc should do the job.

Installation

Dependencies

debugstring depends on the following vim plugins:

  • vim-repeat [OPTIONAL]

Using a runtimepath/package manager

Plugin manager How to install
[Dein][1] call dein#add('bergercookie/vim-debugstring')
[minpac][2] call minpac#add('bergercookie/vim-debugstring')
[Pathogen][3] git clone https://github.com/bergercookie/vim-debugstring.git ~/.vim/bundle/vim-debugstring
[Plug][4] Plug 'bergercookie/vim-debugstring'
[Vundle][5] Plugin 'bergercookie/vim-debugstring'
manual copy all of the files into your .vim directory (or ~/.config/nvim if you're using neovim)

Plugin also utilizes vim-repeat if the latter is installed.

Manual installation

Copy the plugin files to their corresponding directories under ${HOME}/.vim (Linux) or $HOME/vimfiles (Windows).

Contributing

In case you want to contribute on a certain feature/fix, don't hesitate to discuss about it in the Github issues or to implement it and make a PR.

License

Current plugin is distributed under the same terms as Vim itself. See the LICENSE file

Self Promotion

In case you like the plugin, you might as well star it on Github or rate it on vim.org

Notes on Development

This mostly comprises a list of stuff I want to keep track of when developing this or other vim plugins

  • Use vimdoc to generate documentation from the vim docstring (instead of manually updating the .txt file). See the misc/build_doc for more on how this is done.

  • Use vader for unittesting. Use test/run-tests.sh to run them. For this to run you have to first git clone vim-repeat and vim-vader in the root of this repo:

    git clone https://github.com/junegunn/vader.vim.git
    git clone https://github.com/tpope/vim-repeat.git

TODO

  • Method to delete all the debugging strings in current buffer / all "touched" buffers - see far.vim
  • Method to print name and contents of a variable
  • [ ]Make the counter buffer-specific Nope, we already have the filename & line for file-specific text
  • Escape double single quotes vimscript variable printing
  • Append to current line if that is empty
  • Support repeat.vim
  • Use an assertion module - vader
  • Use vader.vim for TDD
  • Extend vader support for rest of languages
  • Use travis for CI
  • Bug with changing the filename of the current file
  • Make vim-repeat dependency optional
  • Turn supported languages into a table - what do we support in which language
  • Make vim-repeat dependency optional