feat(nvim): add function to write and source files
Copied from tjdevries' config_manager repository, add a global `save_and_exec` function that will write and source vim or lua files, and use this within my existing `<leader>so` key mapping.
This commit is contained in:
parent
7d3b82884c
commit
7860c3506a
12
roles/neovim/files/autoload/opdavies.vim
Normal file
12
roles/neovim/files/autoload/opdavies.vim
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
if !exists('*opdavies#save_and_exec')
|
||||||
|
function! opdavies#save_and_exec() abort
|
||||||
|
if &filetype == 'vim'
|
||||||
|
:silent! write
|
||||||
|
:source %
|
||||||
|
elseif &filetype == 'lua'
|
||||||
|
:silent! write
|
||||||
|
:luafile %
|
||||||
|
endif
|
||||||
|
return
|
||||||
|
endfunction
|
||||||
|
endif
|
|
@ -27,7 +27,7 @@ local function set_key_mappings()
|
||||||
|
|
||||||
local options = { noremap = true }
|
local options = { noremap = true }
|
||||||
|
|
||||||
map("n", "<Leader>so", ":luafile ~/.config/nvim/init.lua<Cr>", options)
|
map("n", "<Leader>so", ":call opdavies#save_and_exec()<CR>", options)
|
||||||
|
|
||||||
-- Format paragraphs to an 80 character line length.
|
-- Format paragraphs to an 80 character line length.
|
||||||
map("n", "<Leader>g", "gqap", options)
|
map("n", "<Leader>g", "gqap", options)
|
||||||
|
|
Loading…
Reference in a new issue