Skip to content

vguen/godbolt.nvim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

103 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alt text

godbolt.nvim

Display assembly for the current buffer or visual selection from https://godbolt.org

Requires neovim 0.6 and curl

Setup

You can call the setup function in your config to override these default values:

require("godbolt").setup({
    c = { compiler = "cg112", options = {} },
    cpp = { compiler = "g112", options = {} },
    rust = { compiler = "r1560", options = {} },
    -- any_additional_filetype = { compiler = ..., options = ... },
    quickfix = {
        enable = false, -- whether to populate the quickfix list in case of errors
        auto_open = false -- whether to open the quickfix list if the compiler outputs errors
    }
})

If your neovim config is in lua then place this snippet in your config directly, otherwise place it inside a lua block like so:

lua << EOF
    require("godbolt").setup({
        ...
    })
EOF

options is a table corresponding to the options field in the schema. For example:

  • If you want to add compiler flags then you need to set it to { userArguments = "-Wall -O2" }
  • If you want to use boost then you need to set it to { userArguments = "-I /opt/compiler-explorer/libs/boost_1_77_0", libraries = { id = "boost", version = "1.77.0" } } and so on. -I /opt/compiler-explorer/libs/boost_1_77_0 was for including boost, you can get the path of the library by curling or visiting https://godbolt.org/api/libraries/c++

You can get the list of compiler ids by visiting or curling https://godbolt.org/api/compilers/<language> (or using the fuzzy finders mentioned) and the list of libraries by curling or visiting https://godbolt.org/api/libraries/<language>. For more info, see https://github.com/compiler-explorer/compiler-explorer/blob/main/docs/API.md

(Note: use c++, not cpp for C++)

Usage

Setting b:godbolt_exec to true will execute the code in addition to displaying assembly and display the output/error in the message area.

  • To use the default/setup compiler for the entire buffer:

:Godbolt and type in compiler flags in the prompt if needed

  • To use the default/setup compiler for a visual selection: Select the function(s) you want and

:'<,'>Godbolt

  • To use a custom compiler for the entire buffer:

:GodboltCompiler <compiler>.

  • Similarly, to use a custom compiler for a visual selection: Select the function you want and

:'<,'>GodboltCompiler <compiler>.

  • Adding a bang (!) to either command (:Godbolt!, GodboltCompiler!) will reuse the last assembly window for the current source buffer.

Fuzzy finder integration

If in :GodboltCompiler <compiler> or :'<,'>GodboltCompiler <compiler>, <compiler> is telescope, fzf, skim or fzy, you can choose the compiler using telescope.nvim, fzf, skim or fzy + nvim-fzy respectively.

Quickfix

Set quickfix.enable = true as described above to populate the quickfix in case of errors. If quickfix.auto_open is true, a quickfix list will automatically open if the compiler outputs errors. Otherwise you can manually :copen

Screencast:

asciicast

Demo

asciicast

TODO

  • Update default compilers using Github Actions.

About

Display assembly for the current buffer or visual selection from godbolt.org. Also at https://sr.ht/~p00f/godbolt.nvim

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Fennel 94.4%
  • Makefile 3.2%
  • Vim Script 1.9%
  • Shell 0.5%