Comments (4)
@michaelb Sorry, I was intending to reply to the op, as I came up with the solution and earlier I've seen this issue while researching. I agree the added value is small. I barely wrote this to be able to quickly trigger sniprun with leader based mappings without needing to type commands. This works for me and by all means I'm not a pro, I just wanted to help the person asking the question.
from sniprun.
Besides :%SnipRun
, aka the intended way ??
Not much, except the API (see API.md, run_range) while hacking a little for the end of the range, maybe putting -1 or just a large number will work, I haven't tested
from sniprun.
I think you might appreciate my wrappers:
function SnipRunFlowSnippet()
-- set up state to track if user cancels or accepts
local canceled = false
local accepted = false
-- prompt for selection
print "Select code to run and press ESC to cancel or Return to execute"
-- enter visual lines
vim.cmd "normal! V"
vim.cmd "redraw"
while not canceled and not accepted do
-- loop to do the selection allowing enter, esc or v-block up and down
local char = vim.fn.getchar()
if char == 27 then -- escape
canceled = true
elseif char == 13 then -- return
accepted = true
elseif char == 106 then -- j
vim.cmd "normal! j"
vim.cmd "redraw"
elseif char == 107 then -- k
vim.cmd "normal! k"
vim.cmd "redraw"
end
end
if accepted then
-- HACK: exit visual first to get selection to marks
local esc = vim.api.nvim_replace_termcodes("<esc>", true, false, true)
vim.api.nvim_feedkeys(esc, "x", false)
-- run the snippet
vim.cmd ":'<,'>SnipRun"
end
-- exit visual and confirm cancellation
if canceled then
print "Operation canceled"
local esc = vim.api.nvim_replace_termcodes("<esc>", true, false, true)
vim.api.nvim_feedkeys(esc, "x", false)
end
end
function SnipRunFlowFile()
vim.cmd "normal! ggVG$"
local esc = vim.api.nvim_replace_termcodes("<esc>", true, false, true)
vim.api.nvim_feedkeys(esc, "x", false)
vim.cmd ":'<,'>SnipRun"
end
setting them from bindings in normal 1. in a table:
"<cmd>lua SnipRunFlowSnippet()<CR>",
"Execute SNIPPET with SnipRun",
general_opts,
},
["<leader>cX"] = {
"<cmd>lua SnipRunFlowFile()<CR>",
"Execute FILE with SnipRun",
general_opts,
},```
2. or native:
```vim.api.nvim_set_keymap('n', '<leader>cx', ':lua SnipRunFlowSnippet()<CR>', general_opts)
vim.api.nvim_set_keymap('n', '<leader>cX', ':lua SnipRunFlowFile()<CR>', general_opts)```
from sniprun.
@tom-gora , I don't know if you were addressing me or Wangch29.
I personally don't see very much added value (plus, you might want your script to listen to up/down arrows as well as j/k, this caused me 30s of confusion). If you prefer "command then select" workflow, maybe the "operator mode" (see the friendly manual ) for vim motions will be of interest
Thanks for sharing your script
from sniprun.
Related Issues (20)
- Wrong cache directory path on linux HOT 1
- Wiki pages not working (404) HOT 2
- Check Health Deprecation HOT 1
- SnipRun failed to build in go, if last line is comment.. HOT 1
- add feature can auto add nested local package's function in go . HOT 3
- go file cant process dot import. HOT 2
- api.run_string cant work as expected. HOT 8
- Add a pre process goimports for golang project before really run_string. HOT 3
- Releases contain un-updated `Cargo.lock` file HOT 10
- Releases contain un-updated `Cargo.lock` file HOT 2
- Option to open Terminal in horizontal split HOT 2
- SnipRun is not working on markdown .md files on MacOS HOT 2
- Python3_jupyter not working HOT 3
- Bun Repl HOT 4
- [FEATURE] Explicit configuration for binaries HOT 3
- Error detected while processing function SnipRunLauncher HOT 6
- C+OpenGL ERROR HOT 1
- No Neorg support anymore? HOT 7
- Cpp Compile-Time Error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sniprun.