From 7860c3506ae0dcc0c8c786e311452b7b19885a58 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 9 Jan 2022 23:22:04 +0000 Subject: [PATCH] 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 `so` key mapping. --- roles/neovim/files/autoload/opdavies.vim | 12 ++++++++++++ roles/neovim/files/lua/opdavies/options.lua | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 roles/neovim/files/autoload/opdavies.vim diff --git a/roles/neovim/files/autoload/opdavies.vim b/roles/neovim/files/autoload/opdavies.vim new file mode 100644 index 0000000..449666b --- /dev/null +++ b/roles/neovim/files/autoload/opdavies.vim @@ -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 diff --git a/roles/neovim/files/lua/opdavies/options.lua b/roles/neovim/files/lua/opdavies/options.lua index 935e400..631ccc4 100644 --- a/roles/neovim/files/lua/opdavies/options.lua +++ b/roles/neovim/files/lua/opdavies/options.lua @@ -27,7 +27,7 @@ local function set_key_mappings() local options = { noremap = true } - map("n", "so", ":luafile ~/.config/nvim/init.lua", options) + map("n", "so", ":call opdavies#save_and_exec()", options) -- Format paragraphs to an 80 character line length. map("n", "g", "gqap", options)