在vscode中有个非常好用的插件叫做code runner,它可以运行各种语言的代码片段,非常方便测试一些简单的代码特性。
在neovim中,也有这样的插件,其中sniprun 是用户使用最多的一个插件。
6cd5d200-7957-11eb-8305-bebb3e2da49e.png
安装
通过packer或者vim-plug安装起来非常简单。
packer
use { 'michaelb/sniprun' do="bash install.sh'}
vim-plug
Plug 'michaelb/sniprun', {'do': 'bash install.sh'}
## 配置文件
require'sniprun'.setup({
selected_interpreters = {}, --# use those instead of the default for the current filetype
repl_enable = {}, --# enable REPL-like behavior for the given interpreters
repl_disable = {}, --# disable REPL-like behavior for the given interpreters
interpreter_options = { --# interpreter-specific options, see docs / :SnipInfo <name>
--# use the interpreter name as key
GFM_original = {
use_on_filetypes = {"markdown.pandoc"} --# the 'use_on_filetypes' configuration key is
--# available for every interpreter
},
Python3_original = {
error_truncate = "auto" --# Truncate runtime errors 'long', 'short' or 'auto'
--# the hint is available for every interpreter
--# but may not be always respected
}
},
--# you can combo different display modes as desired and with the 'Ok' or 'Err' suffix
--# to filter only sucessful runs (or errored-out runs respectively)
display = {
"Classic", --# display results in the command-line area
"VirtualTextOk", --# display ok results as virtual text (multiline is shortened)
-- "VirtualText", --# display results as virtual text
-- "TempFloatingWindow", --# display results in a floating window
-- "LongTempFloatingWindow", --# same as above, but only long results. To use with VirtualText[Ok/Err]
-- "Terminal", --# display results in a vertical split
-- "TerminalWithCode", --# display results and code history in a vertical split
-- "NvimNotify", --# display with the nvim-notify plugin
-- "Api" --# return output to a programming interface
},
live_display = { "VirtualTextOk" }, --# display mode used in live_mode
display_options = {
terminal_width = 45, --# change the terminal display option width
notification_timeout = 5 --# timeout for nvim_notify output
},
--# You can use the same keys to customize whether a sniprun producing
--# no output should display nothing or '(no output)'
show_no_output = {
"Classic",
"TempFloatingWindow", --# implies LongTempFloatingWindow, which has no effect on its own
},
--# customize highlight groups (setting this overrides colorscheme)
snipruncolors = {
SniprunVirtualTextOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",cterfg="Black"},
SniprunFloatingWinOk = {fg="#66eeff",ctermfg="Cyan"},
SniprunVirtualTextErr = {bg="#881515",fg="#000000",ctermbg="DarkRed",cterfg="Black"},
SniprunFloatingWinErr = {fg="#881515",ctermfg="DarkRed"},
},
--# miscellaneous compatibility/adjustement settings
inline_messages = 0, --# inline_message (0/1) is a one-line way to display messages
--# to workaround sniprun not being able to display anything
borders = 'single', --# display borders around floating windows
--# possible values are 'none', 'single', 'double', or 'shadow'
live_mode_toggle='off' --# live mode toggle, see Usage - Running for more info
})
## c语言配置
```lua
require'sniprun'.setup({
interpreter_options = {
C_original = {
compiler = "clang"
}
}
}
})
golang 语言配置
require'sniprun'.setup({
interpreter_options = {
Go_original = {
compiler = "gccgo"
}
}
}
})
网友评论