⌨️ A Vim plugin for Swift which provides file detection, syntax highlighting, support for compiling and running tests, and optional support for formatting and linting tools.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
autoload/swift
compiler
doc
ftdetect
ftplugin
plugin
syntax
.gitignore
.vintrc.yaml
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
NOTICE
README.md

README.md

⌨️ swifty-vim

A Vim plugin for Swift which provides file detection, syntax highlighting, support for compiling and running tests, and optional support for formatting and linting tools.

It is inspired by vim-go and rust.vim.

Requirements

Installation

Use one of the following package managers:

  • Vim 8 packages:
    • git clone https://github.com/bluk/swifty-vim ~/.vim/pack/plugins/start/swifty-vim
  • Pathogen:
    • git clone --depth=1 https://github.com/bluk/swifty-vim.git ~/.vim/bundle/swifty-vim
  • vim-plug:
    • Add Plug 'bluk/swifty-vim' to ~/.vimrc
    • :PlugInstall or $ vim +PlugInstall +qall
  • dein.vim:
    • Add call dein#add('bluk/swifty-vim') to ~/.vimrc
    • :call dein#install()
  • Vundle:
    • Add Plugin 'bluk/swifty-vim' to ~/.vimrc
    • :PluginInstall or $ vim +PluginInstall +qall

Features

There are configuration options to customize the behavior of the key mappings and commands.

Swift Package Manager Support

Key mappings and commands such as:

  • :SwiftPMBuild to build the current package source or tests.
  • :SwiftPMTest to run the package tests.
  • :SwiftPMTestFunctionOnly to run the current test under the cursor.
  • :SwiftPMTestGenerateLinuxMain to generate the code to run existing tests on Linux.
  • :SwiftPMGenerateXcodeProject to generate an Xcode project.

SwiftFormat Support

Key mapping and command:

  • :SwiftFormat to format the current file.

SwiftLint Support

Key mapping and command:

  • :SwiftLint to lint the current file.

Sample vimrc Configuration

Add the following to your vimrc:

" Build the current Swift package. If in a 'Tests' directory, also build the tests.
autocmd FileType swift nmap <leader>b <Plug>(swift-spm-build)
" Run the current Swift package tests.
autocmd FileType swift nmap <leader>t <Plug>(swift-spm-test)
" Run the test under the current cursor.
autocmd FileType swift nmap <leader>ft <Plug>(swift-spm-test-function-only)
" Run swift package generate-xcodeproj
autocmd FileType swift nmap <leader>sgx <Plug>(swift-spm-generate-xcodeproj)
" Run swift test --generate-linuxmain
autocmd FileType swift nmap <leader>sgl <Plug>(swift-spm-test-generate-linuxmain)

" Run SwiftFormat on save.
let g:swift_swiftformat_autosave = 1
" Run SwiftLint on save.
let g:swift_swiftlint_autosave = 1
" If there are errors during autosave, add all errors in the quickfix window.
let g:swift_list_type_commands = { 'Autosave': 'quickfix' }

Documentation / Help

Help can be found in the included documentation.

Run :help swifty-vim in Vim. Helptags (:Helptags) may need to be generated for navigation. See your plugin manager or the helptags documentation (:help helptags) for more information.

Related Links

You may be interested in other similar projects:

License

Apache-2.0 License