Skip to content

witekbobrowski/vim-swiftdocstring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

87 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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.