summaryrefslogtreecommitdiff
path: root/.config/nvim/autoload
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/autoload')
-rw-r--r--.config/nvim/autoload/projector.vim42
1 files changed, 42 insertions, 0 deletions
diff --git a/.config/nvim/autoload/projector.vim b/.config/nvim/autoload/projector.vim
new file mode 100644
index 0000000..9c60055
--- /dev/null
+++ b/.config/nvim/autoload/projector.vim
@@ -0,0 +1,42 @@
+" Allows per-project configuration of keybindings.
+" For example, '*.cpp <F5> make' will run make on F5 button push
+" if .cpp file was opened
+let s:commandFormat="au BufReadPost,BufNewFile %s map %s :!%s<CR>"
+
+" Files that plugin searches on startup (relative to pwd)
+let s:allowedConfigPaths=[".vim/config", ".vim.conf", "vim.conf"]
+
+function! s:createCommand(line)
+ let line=split(a:line)
+ return printf(s:commandFormat, line[0], line[1], join(line[2:]))
+endfunction
+
+function! s:parseFile(filename)
+ let commands=[]
+ for line in readfile(a:filename)
+ let commands=commands + [s:createCommand(line)]
+ endfor
+ return commands
+endfunction
+
+function! s:getConfigs()
+ let commands=[]
+ for filename in s:allowedConfigPaths
+ if filereadable(filename)
+ let commands=commands + s:parseFile(filename)
+ endif
+ endfor
+ return commands
+endfunction
+
+function! s:applyConfig(config)
+ for line in a:config
+ execute line
+ endfor
+endfunction
+
+function! projector#init()
+ let config=s:getConfigs()
+ call s:applyConfig(config)
+endfunction
+