https://github.com/bluk/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.
https://github.com/bluk/swifty-vim
swift vim vim-plugin vim-plugins viml
Last synced: 9 months ago
JSON representation
⌨️ 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.
- Host: GitHub
- URL: https://github.com/bluk/swifty-vim
- Owner: bluk
- License: apache-2.0
- Created: 2018-10-30T14:06:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-16T00:45:13.000Z (over 7 years ago)
- Last Synced: 2025-04-12T08:52:34.393Z (about 1 year ago)
- Topics: swift, vim, vim-plugin, vim-plugins, viml
- Language: Vim script
- Homepage:
- Size: 47.9 KB
- Stars: 18
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ⌨️ swifty-vim
A [Vim][vim] plugin for [Swift][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][vim-go] and [rust.vim][rust_vim].
## Requirements
* Vim 8.0.0902 or greater
* [Swift Toolchain][swift_toolchain_install] or Xcode
* (Optional) [SwiftFormat][swiftformat]
* (Optional) [SwiftLint][swiftlint]
## Installation
Use one of the following package managers:
* [Vim 8 packages][vim8pack]:
* `git clone https://github.com/bluk/swifty-vim ~/.vim/pack/plugins/start/swifty-vim`
* [Pathogen][pathogen]:
* `git clone --depth=1 https://github.com/bluk/swifty-vim.git ~/.vim/bundle/swifty-vim`
* [vim-plug][vim-plug]:
* Add `Plug 'bluk/swifty-vim'` to `~/.vimrc`
* `:PlugInstall` or `$ vim +PlugInstall +qall`
* [dein.vim][dein.vim]:
* Add `call dein#add('bluk/swifty-vim')` to `~/.vimrc`
* `:call dein#install()`
* [Vundle][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`:
```vim
" Build the current Swift package. If in a 'Tests' directory, also build the tests.
autocmd FileType swift nmap b (swift-spm-build)
" Run the current Swift package tests.
autocmd FileType swift nmap t (swift-spm-test)
" Run the test under the current cursor.
autocmd FileType swift nmap ft (swift-spm-test-function-only)
" Run swift package generate-xcodeproj
autocmd FileType swift nmap sgx (swift-spm-generate-xcodeproj)
" Run swift test --generate-linuxmain
autocmd FileType swift nmap sgl (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][doc_dir].
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:
* [Upcoming Apple Language Server Protocol support][apple_lsp] for code
completion, jump to definition, etc.
* [swift.vim][swift_vim]
* [vim-swift][vim-swift]
## License
[Apache-2.0 License][license]
[license]: LICENSE
[swift]: https://swift.org
[vim]: https://www.vim.org
[vim-go]: https://github.com/fatih/vim-go
[rust_vim]: https://github.com/rust-lang/rust.vim/
[swift_toolchain_install]: https://swift.org/getting-started/
[swiftformat]: https://github.com/nicklockwood/SwiftFormat
[swiftlint]: https://github.com/realm/SwiftLint
[vim8pack]: http://vimhelp.appspot.com/repeat.txt.html#packages
[pathogen]: https://github.com/tpope/vim-pathogen
[vim-plug]: https://github.com/junegunn/vim-plug
[dein.vim]: https://github.com/Shougo/dein.vim
[vundle]: https://github.com/gmarik/vundle
[doc_dir]: doc/
[swift_vim]: https://github.com/keith/swift.vim
[vim-swift]: https://github.com/toyamarinyon/vim-swift
[apple_lsp]: https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024