├── .gitignore ├── os ├── windows │ ├── vim.ico │ ├── AutoHotkey.exe │ ├── compile.ahk │ └── vim_omni.ahk └── linux │ └── vim_omni.sh ├── plugin └── omnipresence.vim ├── README.md └── autoload └── omnipresence.vim /.gitignore: -------------------------------------------------------------------------------- 1 | /Config.ini 2 | -------------------------------------------------------------------------------- /os/windows/vim.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majkinetor/vim-omnipresence/HEAD/os/windows/vim.ico -------------------------------------------------------------------------------- /os/windows/AutoHotkey.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majkinetor/vim-omnipresence/HEAD/os/windows/AutoHotkey.exe -------------------------------------------------------------------------------- /plugin/omnipresence.vim: -------------------------------------------------------------------------------- 1 | if exists('g:loaded_omnipresence') | finish | en 2 | let s:save_cpo = &cpo | set cpo&vim 3 | 4 | call omnipresence#ensure_running() 5 | 6 | let &cpo = s:save_cpo | unlet s:save_cpo 7 | let g:loaded_omnipresence = 1 8 | -------------------------------------------------------------------------------- /os/windows/compile.ahk: -------------------------------------------------------------------------------- 1 | scriptName := "vim_omni" 2 | SplitPath, A_AhkPath, ,ahk_dir 3 | 4 | RunWait, taskkill /IM %scriptName%.exe 5 | RunWait, %ahk_dir%\Compiler\Ahk2Exe.exe /in %scriptName%.ahk /icon vim.ico 6 | 7 | if (!FileExist(scriptName ".exe")) 8 | MsgBox Compilation failed! 9 | else MsgBox Exe created! 10 | -------------------------------------------------------------------------------- /os/linux/vim_omni.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Deps: 4 | # Ubuntu/Debian : sudo apt-get install xdotool xsel 5 | # RH : yum install xdotool xsel 6 | # OpenSuse : zypper install xdotool xsel 7 | # Mac : sudo port install xdotool 8 | # For hotkey : xkeybind 9 | # "vim_omni" 10 | # Mod2 + F12 11 | 12 | xdotool -< /tmp/vimy 18 | gvim --nofork '+$|set ff=unix|startinsert!' /tmp/vimy 19 | cat /tmp/vimy | xsel -bi 20 | xdotool - <:p:h:h') 5 | let s:Ahk = shellescape(s:RootDir . '/os/windows/AutoHotKey.exe') 6 | let s:AhkScript = shellescape(s:RootDir . '/os/windows/vim_omni.ahk') 7 | 8 | let s:config = s:RootDir . '/Config.ini' 9 | let s:cfg_lines = filereadable(s:config) ? readfile(s:config) : [] 10 | let s:disabled = index(s:cfg_lines, 'disabled=1') != -1 11 | let s:uninstall = index(s:cfg_lines, 'uninstall=1') != -1 12 | 13 | 14 | fu! s:run_ahk() 15 | sil exe '!start ' . s:Ahk . ' ' . s:AhkScript 16 | endf 17 | 18 | fu! s:config_update() 19 | let cfg = s:config_createlist() 20 | if !s:config_shouldUpdate(cfg) | retu | en 21 | call writefile(cfg, s:config) 22 | endfu 23 | 24 | fu! s:config_createlist() 25 | let lines = ['[Config]'] 26 | let lines += [ 'path=' . $VIMRUNTIME . '/gvim.exe'] 27 | 28 | let vars = [ 'hotkey', 'vimoptions', 'uninstall', 'disabled' ] 29 | for var in vars 30 | let g_var = 'g:omnipresence_' . var 31 | let s_var = 's:' . var 32 | if exists(g_var) | let lines += [ printf('%s=%s', var, eval(g_var)) ] | en 33 | if exists(s_var) | let lines += [ printf('%s=%s', var, eval(s_var)) ] | en 34 | endfor 35 | retu lines 36 | endfu 37 | 38 | fu! s:config_shouldUpdate(cfg) 39 | if !filereadable(s:config) | retu 1| en 40 | let lines = readfile(s:config) 41 | 42 | let a = join(lines, '\n') 43 | let b = join(a:cfg, '\n') 44 | 45 | retu a!=b 46 | endfu 47 | 48 | 49 | fu! omnipresence#ensure_running() 50 | if s:uninstall | retu | en 51 | 52 | call s:config_update() 53 | if has('win32') 54 | call s:run_ahk() 55 | en 56 | endfu 57 | 58 | fu! omnipresence#toggle() 59 | let s:disabled = !s:disabled 60 | call s:config_update() 61 | endfu 62 | 63 | fu! omnipresence#uninstall() 64 | let s:uninstall=1 65 | call s:config_update() 66 | endfu 67 | 68 | let &cpo = s:save_cpo | unlet s:save_cpo 69 | let g:loaded_omnipresence = 1 70 | -------------------------------------------------------------------------------- /os/windows/vim_omni.ahk: -------------------------------------------------------------------------------- 1 | #Persistent 2 | #SingleInstance, ignore ;strange: if you change this to force, RunWait gvim doesn't return ever... 3 | GetParams() 4 | if (g_uninstall) 5 | Uninstall() 6 | else Install() 7 | 8 | g_traytip = Vim hotkey launcher (press %g_HotKey%).`nInstalled by vim plugin vim-omnipresence. 9 | if (!g_disabled) 10 | Hotkey, %g_HotKey%, Launch_vim 11 | else 12 | g_traytip = Vim hotkey launcher is DISABLED.`n`nTo enable it execute ':call omnipresence#toggle()' from within vim. 13 | 14 | Menu, Tray, Icon, vim.ico,,1 15 | Menu, Tray, Tip, % g_traytip 16 | 17 | SetTimer, CheckConfig, 2000 18 | return 19 | 20 | CheckConfig: 21 | FileGetTime, _, %g_config%, M 22 | if (_== g_cfgTime) 23 | return 24 | Reload 25 | return 26 | 27 | Launch_vim: 28 | g_activeHwnd := WinExist("A") 29 | fname := GetNewFileName() 30 | saved_clipboard := clipboard 31 | Send, ^a^c 32 | ClipWait, 1 33 | content := clipboard 34 | 35 | FileAppend, %content%, %fname%, UTF-8 36 | FileGetTime, ftime_pre, %fname%, M 37 | RunWait %g_path% %g_vimoptions% -- "%fname%" 38 | FileGetTime, ftime_post, %fname%, M 39 | if ( ftime_pre == ftime_post ) 40 | return 41 | 42 | FileRead, content, %fname% 43 | FileDelete, %fname% ; delete for now, maybe save later 44 | content := RegExReplace(content, "`r`n$", "") ; remove ending new line because FileRead adds one 45 | clipboard := content 46 | 47 | WinActivate, ahk_id %g_activeHwnd% 48 | WinWaitActive, ahk_id %g_activeHwnd% 49 | Send, ^v 50 | 51 | clipboard := saved_clipboard 52 | return 53 | 54 | GetParams() { 55 | local cfgSection, i, k 56 | 57 | ; Default values 58 | g_config := A_ScriptDir . "\..\..\config.ini" 59 | g_vimoptions = "+set ff=dos fenc=utf-8 spell" "+$" "+startinsert!" 60 | g_vimoptions = "+set ff=dos fenc=utf-8" "+$" 61 | g_hotkey := "F12" 62 | g_path := A_ProgramFiles "\vim\vim74\gvim.exe" 63 | 64 | ; Parse config 65 | IniRead, cfgSection, %g_config%, Config 66 | Loop, parse, cfgSection, `n, `r 67 | i := InStr(A_LoopField,"="), k := SubStr(A_LoopField, 1, i-1), g_%k% := SubStr(A_LoopField, i+1) 68 | 69 | FileGetTime, g_cfgTime, %g_config%, M 70 | } 71 | 72 | GetNewFileName() { 73 | EnvGet, TEMP, TEMP 74 | FormatTime, time, , yyMMdd-HHmmss 75 | return TEMP . "\mm_vim_aw" . time 76 | } 77 | 78 | Install() { 79 | lnk = %A_Startup%\%A_ScriptName%.lnk 80 | if !FileExist(lnk) 81 | FileCreateShortcut, %A_ScriptDir%\AutoHotkey.exe, %lnk% , %A_ScriptDir%, %A_ScriptFullPath% 82 | } 83 | 84 | Uninstall() { 85 | 86 | lnk = %A_Startup%\%A_ScriptName%.lnk 87 | if FileExist(lnk) 88 | { 89 | Msgbox Vim-omnipresence is going to be uninstalled. 90 | FileDelete, %lnk% 91 | } 92 | else Msgbox Vim-omnipresence is uninstalled.`n`nTo enable it delete 'Config.ini' file and enable vim plugin in your .vimrc . 93 | Exit 94 | } 95 | --------------------------------------------------------------------------------