feat(nvim) run script by shebang on keymap ',rs'
This commit is contained in:
parent
73edbd8ae4
commit
d19839a894
@ -80,6 +80,7 @@ echo "Hello $USER!"
|
|||||||
| <kbd>,qa</kbd> | Close all without saving |
|
| <kbd>,qa</kbd> | Close all without saving |
|
||||||
| <kbd>,t</kbd> | Tagbar |
|
| <kbd>,t</kbd> | Tagbar |
|
||||||
| <kbd>,rr</kbd> | Run script in new tab (python, go, preview markdown)|
|
| <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) |
|
| <kbd>,rf</kbd> | Format file (go, rust) |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -19,9 +19,18 @@ local function set_keymap_format_file(cmd)
|
|||||||
set_keymap_base("f", cmd_string)
|
set_keymap_base("f", cmd_string)
|
||||||
end
|
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 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_run_script_base("r", cmd)
|
||||||
set_keymap_base("r", cmd_string)
|
end
|
||||||
|
|
||||||
|
local function set_keymap_run_script_by_shebang(cmd)
|
||||||
|
set_keymap_run_script_base("s", cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_function_autocmd_by_filetype(set_keymap_func, ft, cmd)
|
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('rust', 'cargo fmt -p')
|
||||||
autocmd_format_file_by_filetype('go', 'go fmt')
|
autocmd_format_file_by_filetype('go', 'go fmt')
|
||||||
|
|
||||||
|
autocmd(function() set_keymap_run_script_by_shebang([[$(head -1 % | cut -c 3-) %]]) end)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user