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.
- Vim 8.0.0902 or greater
- Swift Toolchain or Xcode
- (Optional) SwiftFormat
- (Optional) SwiftLint
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
- Add
- dein.vim:
- Add
call dein#add('bluk/swifty-vim')
to~/.vimrc
:call dein#install()
- Add
- Vundle:
- Add
Plugin 'bluk/swifty-vim'
to~/.vimrc
:PluginInstall
or$ vim +PluginInstall +qall
- Add
There are configuration options to customize the behavior of the key mappings and commands.
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.
Key mapping and command:
:SwiftFormat
to format the current file.
Key mapping and command:
:SwiftLint
to lint the current file.
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' }
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.
You may be interested in other similar projects:
- Upcoming Apple Language Server Protocol support for code completion, jump to definition, etc.
- swift.vim
- vim-swift