Vim runtime files for Swift

Related tags

Editor vim swift viml
Overview

Swift.vim

Syntax and indent files for Swift

If you don't have a preferred installation method check out vim-plug.

Examples

Syntastic Integration

swift.vim can show errors inline from swift package manager or from swiftlint using syntastic.

Usage

  • Install syntastic

  • swiftpm integration will be automatically enabled if you're running vim from a directory containing a Package.swift file.

  • SwiftLint integration will be automatically enabled if you have SwiftLint installed and if you're running vim from a directory containing a .swiftlint.yml file.

  • To enable both at once add this to your vimrc:

let g:syntastic_swift_checkers = ['swiftpm', 'swiftlint']
Comments
  • Modules from `.swift` files in the same target aren't recognized.

    Modules from `.swift` files in the same target aren't recognized.

    I apologize in advance if I'm missing something obvious, but I've been unable to figure this out on my own. If, for example, I have:

    // foo.swift
    class Foo {}
    

    and

    // bar.swift
    let foo = Foo()
    

    where foo.swift and bar.swift are in the same target, it complains that it doesn't recognize Foo when Foo is used in bar.swift. How do I configure this plugin to see other modules in the same target?

    opened by bpeabody 15
  • Massively update indentation

    Massively update indentation

    This is a massive change to how indentation works. This removes the previous function and replaces it with a new one. Originally I wanted to rely on cindent more here but after spending some time with it, it really isn't right for swift. Still, falling back to it is better than handling all of the cases. This could still use some massive refactoring but I want it to get tested a little first.

    opened by keith 14
  • Support Ctags

    Support Ctags

    It'll be nice to set up ctags with this plugin. But I'm not familiar with Vim plugin dev.

    Here is my .ctags config:

    --langdef=Swift 
    --langmap=Swift:+.swift 
    --regex-swift=/enum[ \t]+([^\{\}]+).*$/\1/n,enum,enums/ 
    --regex-swift=/typealias[ \t]+([^:=]+).*$/\1/t,typealias,typealiases/ 
    --regex-swift=/protocol[ \t]+([^:\{]+).*$/\1/p,protocol,protocols/
    --regex-swift=/struct[ \t]+([^:\{]+).*$/\1/s,struct,structs/ 
    --regex-swift=/class[ \t]+([^:\{]+).*$/\1/c,class,classes/ 
    --regex-swift=/func[ \t]+([^\(\)]+)\([^\(\)]*\)/\1/f,function,functions/ 
    --regex-swift=/(var|let)[ \t]+([^:=]+).*$/\2/v,variable,variables/ 
    --regex-swift=/^[ \t]*extension[ \t]+([^:\{]+).*$/\1/e,extension,extensions/
    

    And .vimrc:

    " tagbar
    nmap <F8> :TagbarToggle<CR>
    let g:tagbar_type_swift = {
      \ 'ctagstype': 'swift',
      \ 'kinds' : [
        \ 'n:Enums',
        \ 't:Typealiases',
        \ 'p:Protocols',
        \ 's:Structs',
        \ 'c:Classes',
        \ 'f:Functions',
        \ 'v:Variables',
        \ 'e:Extensions'
      \ ],
      \ 'sort' : 0
    \ }
    

    Here is how it looks like: screen shot 2015-12-08 at 11 12 37 am

    opened by lexrus 11
  • Highlight @available/#available attributes

    Highlight @available/#available attributes

    This adds the new (introduced in Swift 2) @available and #available attributes to the swift syntax file.

    I chose to add this to the new swiftConditionalAttribute (since it's a conditional attribute that is used in if/guard statements) rather than the existing swiftAttributes (which are typically used to apply to functions/classes).

    If you think that's wrong, I can easily update this.

    Resolves #54

    opened by ackyshake 10
  • Indent on multiline function declaration

    Indent on multiline function declaration

    Try indenting:

      override func observeValueForKeyPath(keyPath: String!,
                                           ofObject object: AnyObject!, 
                                           change: NSDictionary!, 
                                           context: CMutableVoidPointer) {
        println("CHANGE OBSERVED: \(change)")
      }
    

    Result:

      override func observeValueForKeyPath(keyPath: String!,
                                           ofObject object: AnyObject!, 
                                                    change: NSDictionary!, 
                                                            context: CMutableVoidPointer) {
                                                              println("CHANGE OBSERVED: \(change)")
                                                            }
    
    opened by devth 9
  • Syntax highlighting using SourceKit

    Syntax highlighting using SourceKit

    SourceKit can now be built under Linux out of the box.

    Have you though about using it (via SourceKitten or directly?) not only for autocompletion, but also for syntax highlighting? Or may be there are reasons to avoid it?

    opened by romix 8
  • Indentation Problem?

    Indentation Problem?

    Hi! Thanks for this awesome vim plugin. Color syntax's works pretty well but I'm facing indentation issues. Take as an example the code below.

    enum Pepper {                                                                                                                                                   
        case Paprika, RedPepper, HabaneroChili, KomodoDragonChiliPepper
    }
    
    func heatUnits(pepper: Pepper) -> String {
        switch pepper {
        case .Paprika:
            return "πŸ”₯" 
        case .RedPepper:
            return "πŸ”₯πŸ”₯πŸ”₯πŸ”₯"
        case .HabaneroChili:
            return "πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯"
        case .KomodoDragonChiliPepper:
            return "πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯"
    }
    

    when I ident it gg=G it becomes:

    enum Pepper {                                                                                                                                                   
    case Paprika, RedPepper, HabaneroChili, KomodoDragonChiliPepper
    }
    
    func heatUnits(pepper: Pepper) -> String {
    switch pepper {
    case .Paprika:
    return "πŸ”₯"
    case .RedPepper:
    return "πŸ”₯πŸ”₯πŸ”₯πŸ”₯"
    case .HabaneroChili:
    return "πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯"
    case .KomodoDragonChiliPepper:
    return "πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯"
    }
    

    Am I missing something? I'm using the El Capitan's VIM:

    $ vim --version
    VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Apr  5 2016 14:53:37)
    Compiled by [email protected]
    

    Thank you!

    opened by ornithocoder 8
  • Multiline function indentation conflicts with closure syntax

    Multiline function indentation conflicts with closure syntax

    So, a fun task is running gg=G on every Swift file and seeing what happens…

    UIView.animateWithDuration(0.4, animations: {
                               view.backgroundColor = UIColor.redColor()
    })
    

    I see this style was decided on in #19, but personally I prefer wrapping multiline function calls like this:

    someFunction(with: 1, a: 2, lot: 3, of: 4, parameters: 5,
        objectiveCPrefersLengthyExternalParameterNames: true)
    

    because it's lessing jarring to my eyes, and also because Objective-C APIs don't play well with the "Python" style. Would this fix the closure issue?

    opened by aclissold 6
  • Fix highlighting for underscore separated numbers

    Fix highlighting for underscore separated numbers

    "The Basics" chapter of the official "The Swift Programming Language" book states that you can pad numbers with underscores to help readability.

    This commit also handles the case where underscore padded numbers can also contain a period (i.e., underscore padded float/double)

    Additionally, added some underscore padded numbers in example/swift.vim for testing purposes.

    Fixes #51

    opened by ackyshake 6
  • Basic indentation issue

    Basic indentation issue

    Curly braces are not un-indenting correctly for me. It comes out like this:

            if(true){
                }else{
                    }
    

    I would expect it to be like this

            if(true){
            }else{
            }
    

    I have tried enabling cindent, autoindent, and smartindent. Doesn't seem to have any effect

    opened by vishl 6
  • ? and ! included as keywords makes optional type names not searchable easily

    ? and ! included as keywords makes optional type names not searchable easily

    ftplugin/swift.vim includes ? and ! as keywords: setlocal iskeyword+=?,!,@-@,#

    which makes optional types different from the non-optional version. So if I place the cursor over UICollectionView in the line for v1 and hit keys like gd, or *, it doesn't match the lines for v2 and v3. Vice versa.

    var v1: UICollectionView
    var v2: UICollectionView?
    var v3: UICollectionView!
    

    Seems better to set keywords like so: setlocal iskeyword+=@-@,#

    Any reason why ! and ? are included?

    opened by hboon 6
  • Indentation for nested switch/case and for cases with code on the same line is incorrect.

    Indentation for nested switch/case and for cases with code on the same line is incorrect.

    The following Swift file

    switch readLine() {
    case "1": print("1")
    case "2":
    print("2")
    case "a": 
    switch readLine() {
    case "1": print("1")
    default: print("Other")
    }
    default: print("Other")
    }
    

    (there is whitespace in "a":) is indented like so

    switch readLine() {
        case "1": print("1")
    case "2":
        print("2")
        case "a": 
        switch readLine() {
            case "1": print("1")
            default: print("Other")
        }
        default: print("Other")
    }
    

    The expected behavior is for it to be indented as so:

    switch readLine() {
    case "1": print("1")
    case "2":
        print("2")
    case "a": 
        switch readLine() {
        case "1": print("1")
        default: print("Other")
        }
    default: print("Other")
    }
    

    The detection for cases appears to expect the : to end the line, which is not required by Swift, and it appears to align a case with the previous use of switch instead of the switch it is actually part of. The syntax highlighting still appears correct.

    opened by deatondg 1
  • swiftAttributes detected incorrectly.

    swiftAttributes detected incorrectly.

    This is working:

    init(t: type, f: @escaping () -> String)
    

    @escaping is completely highlighted as swiftAttributes.

    This is not working:

    init(t: Type, f: @escaping () -> String)
    

    @ is highlighted as swiftAttributes, escaping is highlighted as swiftInterpolatedString

    (Same goes for functions instead of inits)

    opened by jandamm 0
  • Add Code Folding Support

    Add Code Folding Support

    I just installed swift.vim in neovim 0.4.3. My swift files compile and run fine in Swift version 5.3-dev (LLVM 55d27a5828, Swift 6a5d84ec08).

    But vim doesn't find any folds in my swift files. When I press one of the commands to open or close folds, such as zO or zc, I see the error E490: No fold found. This is unusual. Most languages have code folding support in vim.

    opened by xanderdunn 3
  • Is there a way to get syntax checker working outside of a package?

    Is there a way to get syntax checker working outside of a package?

    I'm new to swift so I'm not familiar with how things are supposed to work. Is there a way to get syntax errors to show up when editing a standalone file?

    Similarly, if I edit a file that's part of an xcode project, is there a way to get syntax errors to display?

    So far, I've only gotten this to work after init'ing a package and then editing Source/package/main.swift

    opened by sdondley 12
  • Match more docstrings

    Match more docstrings

    Previously, certain keywords in comments would be left unmatched if the docstring was written as multiple single-line comments or if the comments began with an asterisk. For example:

    /**
     * Function description
     * - Parameter a: parameter description
     * - Returns: return value description
     */
    

    or

    /// Function description
    /// - Parameter a: parameter description
    /// - Returns: return value description
    

    This pull request fixes that, and furthermore introduces two new syntax groups: swiftDocStringParam, which matches parameter names in docstrings, and swiftDocStringInlineCode which matches text surrounded by back-ticks in comments. Those two groups are highlighted with SpecialComment by default, but by overriding them users should be able to get closer to the way Xcode displays comments.

    Below is a screenshot with the improved highlighting: Screen Shot 2019-12-28 at 12 20 11 Note how - Returns and - Parameter are highlighted in bold, and the parameter name and the zero in the last line are highlighted in a lighter colour.

    opened by hristost 0
Owner
Keith Smiley
iOS @Lyft
Keith Smiley
Emacs support for Apple's Swift programming language.

swift-mode Major-mode for Apple's Swift programming language. Installation Install swift-mode package from MELPA. To install without MELPA, download l

null 347 Dec 17, 2022
A modern Swift (5.6) syntax definition for Sublime Text 4

Swift for Sublime This is a WIP version of a modern Swift (5.6) syntax for Sublime Text 4. It uses the latest features of the Sublime Text syntax engi

Will Bond 13 Dec 5, 2022
πŸͺž Swift wrapper for CodeMirror 6

?? Swift wrapper for CodeMirror 6

khoi 4 Jan 3, 2023
Swift-compute-runtime - Swift runtime for Fastly Compute@Edge

swift-compute-runtime Swift runtime for Fastly Compute@Edge Getting Started Crea

Andrew Barba 57 Dec 24, 2022
Runtime Mobile Security (RMS) πŸ“±πŸ”₯ - is a powerful web interface that helps you to manipulate Android and iOS Apps at Runtime

Runtime Mobile Security (RMS) ?? ?? by @mobilesecurity_ Runtime Mobile Security (RMS), powered by FRIDA, is a powerful web interface that helps you to

Mobile Security 2k Dec 29, 2022
A solid language pack for Vim.

A collection of language packs for Vim. One to rule them all, one to find them, one to bring them all and in the darkness bind them. It won't affect y

Adam Stankiewicz 5.2k Jan 2, 2023
XVim2 - Vim key-bindings for Xcode 9

XVim2 XVim2 is a Vim plugin for Xcode intending to offer a compelling Vim experience without the need to give up any Xcode features. Xcode 9 or above,

null 2.3k Jan 1, 2023
Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files.

Installation β€’ Configuration β€’ Usage β€’ Build Script β€’ Donation β€’ Migration Guides β€’ Issues β€’ Contributing β€’ License BartyCrouch BartyCrouch incrementa

Flinesoft 1.3k Jan 1, 2023
A Swift sample code to reads ISO 10303-21 exchange structures (STEP P21 files for AP242) split into multiple files using external references approach.

multipleP21ReadsSample A Swift sample code to reads ISO 10303-21 exchange structures (STEP P21 files for AP242) split into multiple files using extern

Tsutomu Yoshida 1 Nov 23, 2021
NotionDrive - A swift package that can upload files to Notion.so or download files from Notion.so

NotionDrive NotionDrive is a swift package that can upload files to Notion.so or

Underthestars-zhy 4 Apr 9, 2022
BeatboxiOS - A sample implementation for merging multiple video files and/or image files using AVFoundation

MergeVideos This is a sample implementation for merging multiple video files and

null 3 Oct 24, 2022
Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway

Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway deployed on Graviton arm64 build swift:5.6.2-amazonlinux2-docker image

Furqan 2 Aug 16, 2022
πŸ’‘ A light Swift wrapper around Objective-C Runtime

A light wrapper around Objective-C Runtime. What exactly is lumos? lumos as mentioned is a light wrapper around objective-c runtime functions to allow

Suyash Shekhar 139 Dec 19, 2022
Swift-friendly API for a set of powerful Objective C runtime functions.

ObjectiveKit ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions. Usage To use ObjectiveKit: Import Objecti

Roy Marmelstein 850 Oct 25, 2022
Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

Apple 4.1k Dec 28, 2022
Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

Apple 4.1k Jan 6, 2023
A cross-platform Swift library for evaluating mathematical expressions at runtime

Introduction What? Why? How? Usage Installation Integration Symbols Variables Operators Functions Arrays Performance Caching Optimization Standard Lib

Nick Lockwood 738 Jan 7, 2023
A Swift Runtime library for viewing type info, and the dynamic getting and setting of properties.

Runtime is a Swift library to give you more runtime abilities, including getting type metadata, setting properties via reflection, and type constructi

Wes Wickwire 970 Jan 3, 2023
Injectionforxcode - Runtime Code Injection for Objective-C & Swift

Injection Plugin for Xcode Copyright (c) John Holdsworth 2012-19 TLDR: Xcode is an integrated development environment (IDE) for macOS containing a sui

John Holdsworth 6.5k Dec 29, 2022