feat(nvim) run script by shebang on keymap ',rs'

This commit is contained in:
TheK4n 2023-01-30 00:41:45 +03:00
parent 73edbd8ae4
commit d19839a894
2 changed files with 14 additions and 2 deletions

View File

@ -80,6 +80,7 @@ echo "Hello $USER!"
| <kbd>,qa</kbd> | Close all without saving |
| <kbd>,t</kbd> | Tagbar |
| <kbd>,rr</kbd> | Run script in new tab (python, go, preview markdown)|
| <kbd>,rs</kbd> | Run script in new tab by shebang |
| <kbd>,rf</kbd> | Format file (go, rust) |

View File

@ -19,9 +19,18 @@ local function set_keymap_format_file(cmd)
set_keymap_base("f", cmd_string)
end
local function set_keymap_run_script_base(key, cmd)
local run_script_string = [[:tabnew %% <CR> :terminal %s %% <CR> :set nocursorline number norelativenumber <CR> G <CR>]]
local cmd_string = string.format(run_script_string, cmd)
set_keymap_base(key, cmd_string)
end
local function set_keymap_run_script(cmd)
local cmd_string = string.format([[:tabnew %% <CR> :terminal %s %% <CR> :set nocursorline number norelativenumber <CR> G <CR>]], cmd)
set_keymap_base("r", cmd_string)
set_keymap_run_script_base("r", cmd)
end
local function set_keymap_run_script_by_shebang(cmd)
set_keymap_run_script_base("s", cmd)
end
local function create_function_autocmd_by_filetype(set_keymap_func, ft, cmd)
@ -58,3 +67,5 @@ autocmd(create_function_autocmd_by_filename(set_keymap_run_script, 'manpage', 'm
autocmd_format_file_by_filetype('rust', 'cargo fmt -p')
autocmd_format_file_by_filetype('go', 'go fmt')
autocmd(function() set_keymap_run_script_by_shebang([[$(head -1 % | cut -c 3-) %]]) end)