Skip to content

Latest commit

 

History

History
122 lines (91 loc) · 4.02 KB

README.md

File metadata and controls

122 lines (91 loc) · 4.02 KB

⌨️ 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