Skip to content

Fast, typesafe, Vim plugins with the power of Swift!

License

Notifications You must be signed in to change notification settings

swift-vim/SwiftForVim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftForVim

Fast, typesafe, Vim plugins with the power of Swift!

SwiftForVim integrates the Swift Programming Language into Vim.

Vim API

Vim

Vimscript <-> Swift

Calling Vim commands from Swift

Vim.command("echo 'Hello World!'")

Evaluating Vim expressions from Swift

let path = String(Vim.eval("expand('%:p')"))

Call Swift functions from Vim

VimPlugin.setCallable("cursorMoved") {
    _ in
    print("The cursor moved")
}

// Off in VimScript
call s:SwiftVimEval("MyAwesomePlugin.invoke('cursorMoved')")

VimAsync

Threading and Async support for Vim

DispatchQueue.async {
    // Do some work
    VimTask.onMain {
        Vim.command("echo 'Hello World! on the main thread.'")
    }
}

Note: VimAsync depends on Foundation. Its not needed for basic, single threaded plugins.

Usage

First, generate a Vim Plugin setup to use Swift.

git clone https://github.com/swift-vim/SwiftForVim.git
cd SwiftForVim
plugin_path=/path/to/MyAwesomePlugin make generate

Then, build the plugin.

cd /path/to/MyAwesomePlugin
make

Last, setup the plugin ( VimPlug, Pathogen, etc ).

Design Goals

Portable, fast, and simple to use.

It doesn't require recompiling Vim or a custom fork of the Swift language.

Why?

Swift makes it easy to build fast, type safe programs, that are easy to debug and deploy.

Examples

The source tree contains a very basic example and test case.

SwiftPackageManger.vim is the canonical use case and uses VimAsync to run a custom RPC service inside of vim.