GitHunt
WI

witekbobrowski/vim-swiftdocstring

๐Ÿ“‘ Vim plugin for generating docstrings in Swift sources

vim-swiftdocstring

screenshot

Version Contact

A simple vim/neovim plugin that provides Xcode-like docstring templates for Swift

Features

  • ๐Ÿ“‘ Generate Swift docstrings for types, functions and properties
  • ๐ŸŽ› Support for /// and /** ... */ delimiters
  • ๐ŸŽจ Even more customizable output
  • ๐Ÿ”จ Xcode-like style of docstrings
  • ๐Ÿง  Better context awarness than in Xcode
  • ๐Ÿ”ฅ Fast parsing using regular expressions
  • ๐Ÿ‘Œ Zero dependency (100% vim-script)

Installation

vim-plug
Plug 'witekbobrowski/vim-swiftdocstring'
Vundle
Plugin 'witekbobrowski/vim-swiftdocstring'
Dein
call dein#add('witekbobrowski/vim-swiftdocstring')

Usage

Commands
  • :SwiftDocstringCurrent

    Generates docstring for the context in the current line of the cursor

  • :SwiftDocstringTypes

    Generates docstrings for every type declaration in current buffer

  • :SwiftDocstringFunctions

    Generates docstrings for every function declaration in current buffer

Mappings

For your own convenience add the following to your .vimrc

" Generate docstring for current context on 'Tab' + '/'
autocmd Filetype swift nnoremap <silent><tab>/ :SwiftDocstringCurrent<CR>
Options

For customized behaviour, change values of these properties. Values presented
below are the defaults.

" Use Multi-line delimiter '/** ... */' instead of single-line '///'
" Boolen value (0 or 1)
let g:swiftdocstring#use_multi_line_delimiter = 0
" Set indentation for dosctring between the text and delimiters
" Integer value (>=0)
let g:swiftdocstring#text_indentation_level = 1
" Use placeholders for some components of the docstring 
" Boolen value (0 or 1)
let g:swiftdocstring#use_placeholders = 1
" Placeholders to be used if setting above is set as true 
" Two element string array
let g:swiftdocstring#placeholder_template = ['<#', '#>']

Documentation

Everything you need to know about the usage of this plugin is basically here
in this readme. Feel free to dive into the codebase for more answers. Very
basic documentation is available from inside of vim itself with :h command.

:help swiftdocstring

Why

This plugin was made under the desire to have a powerful Swift development
environment in vim. Although the plugin brings only a small feature ported
from Xcode, I want to add at least one brick to the wall. This is as far as
I can go at the moment with the amount of time it took to create this piece
of code. I intend it to remain simple, yet useful. Contributions are welcomed.

Resources

To learn more about Swift docstrings read this awesome article at NSHipster:
Swift Documentation

Swift Documentation

Written by Nate Cook & Mattt โ€” July 11th, 2018 (revised)

License

The plugin in licensed under MIT license so do what ever you want with it.

Languages

Vim Script100.0%

Contributors

MIT License
Created October 20, 2018
Updated October 16, 2025