All Projects → sdiehl → vim-ormolu

sdiehl / vim-ormolu

Licence: MIT License
Plugin for formatting Haskell source code

Programming Languages

Vim Script
2826 projects

Projects that are alternatives of or similar to vim-ormolu

Vim Gofmt
Formats Go source code asynchronously with multiple Go formatters.
Stars: ✭ 11 (-68.57%)
Mutual labels:  formatter, vim-plugin
Vim Clang Format
Vim plugin for clang-format, a formatter for C, C++, Obj-C, Java, JavaScript, TypeScript and ProtoBuf.
Stars: ✭ 837 (+2291.43%)
Mutual labels:  formatter, vim-plugin
vim-nicomment
[Unmaintained] Flow comments on your Vim
Stars: ✭ 16 (-54.29%)
Mutual labels:  vim-plugin
canonix
Experiment in Nix formatting
Stars: ✭ 18 (-48.57%)
Mutual labels:  formatter
react-numeric
A react component for formatted number form fields
Stars: ✭ 30 (-14.29%)
Mutual labels:  formatter
vim-jqplay
Run jq interactively in Vim
Stars: ✭ 56 (+60%)
Mutual labels:  vim-plugin
vim-bettergrep
A better way to grep in vim.
Stars: ✭ 15 (-57.14%)
Mutual labels:  vim-plugin
gh.vim
Vim/Neovim plugin for GitHub
Stars: ✭ 149 (+325.71%)
Mutual labels:  vim-plugin
lucene
Node.js lib to transform: lucene query → syntax tree → lucene query
Stars: ✭ 61 (+74.29%)
Mutual labels:  formatter
VimConfig
Configuration files for Vi-IMproved.
Stars: ✭ 23 (-34.29%)
Mutual labels:  vim-plugin
nerdtree-visual-selection
Defines commands that will work on files inside a Visual selection
Stars: ✭ 48 (+37.14%)
Mutual labels:  vim-plugin
vim-inccomplete
Vim plugin for #include directive completion.
Stars: ✭ 14 (-60%)
Mutual labels:  vim-plugin
YankAssassin.vim
Don't let the cursor move while Yanking in Vim/Neovim
Stars: ✭ 50 (+42.86%)
Mutual labels:  vim-plugin
stan-vim
A Vim plugin for the Stan probabilistic programming language.
Stars: ✭ 41 (+17.14%)
Mutual labels:  vim-plugin
AutoFormatInputWatcher
This repository contains input watcher for auto formatting digits in edit text
Stars: ✭ 15 (-57.14%)
Mutual labels:  formatter
Fmt.jl
Python-style format strings for Julia
Stars: ✭ 31 (-11.43%)
Mutual labels:  formatter
vim-backscratch
Small scratches for Vim, feels nice
Stars: ✭ 20 (-42.86%)
Mutual labels:  vim-plugin
formatters
A javascript library for formatting and manipulating.
Stars: ✭ 14 (-60%)
Mutual labels:  formatter
lancer
Turn your python code into a hideous mess. Ever heard of Black? This is the opposite.
Stars: ✭ 179 (+411.43%)
Mutual labels:  formatter
mpi
minimal (n)vim plugins - icons (Under 200 LOC)
Stars: ✭ 32 (-8.57%)
Mutual labels:  vim-plugin

vim-ormolu

Introduction

This is a plugin to integrate ormolu or fourmolu into your vim workflow. It will run ormolu on Haskell buffers every time they are saved similar to gofmt. It requires ormolu be accessible from your $PATH.

Installation

First install ormolu via Cabal, Stack or Nix:

$ stack install ormolu --resolver=lts-15.10   # via stack
$ cabal new-install ormolu --installdir=/home/user/.local/bin # via cabal
$ nix-build -A ormolu   # via nix

If you are using pathogen.vim unpack this repository into your vim or neovim configuration directory.

$ cd ~/.vim/bundle         # for vim
$ cd ~/.config/nvim/bundle # for neovim
$ git clone https://github.com/sdiehl/vim-ormolu.git

If you are using Vundle add the following to your configuration file:

"Haskell Formatting
Plugin 'sdiehl/vim-ormolu'

If you are using vim-plug add the following to your configuration file:

"Haskell Formatting
Plug 'sdiehl/vim-ormolu'

Configuration

The default settings will work fine out of the box without any aditional configuration.

If you have a non-standard $PATH then set g:ormolu_command Vim variable to the location of the ormolu binary. For example if you want to use fourmolu instead pass this as the argument.

let g:ormolu_command="fourmolu"

When using fourmolu with a configuration file, fourmolu prefixes output with a "Loaded config from: ..." message. In order to prevent this from being included in the reformatted file, set

let g:ormolu_suppress_stderr=1

The specific flags for Ormolu can be configured by changing the Vim variable g:ormolu_options. For example to use faster and unsafe formatting:

let g:ormolu_options=["--unsafe"]

To disable the formatting on a specific buffer use let b:ormolu_disable=1.

To disable the formatting globally use let g:ormolu_disable=1.

If instead of formatting on save, you wish to bind formatting to a specific keypress add the following to your .vimrc or init.vim. For example to bind file formatting to the key sequence tf use:

nnoremap tf :call RunOrmolu()<CR>

To toggle Ormolu formatting on a buffer to use:

nnoremap to :call ToggleOrmolu()<CR>

To disable Ormolu formatting to td use:

nnoremap td :call DisableOrmolu()<CR>

To enable Ormolu formatting to te use:

nnoremap te :call EnableOrmolu()<CR>

To format a visual block range call OrmoluBlock() function. Ormolu doesn't normally work this way and usually requires more context on the module to format. So this feature is experimental and may not function as expected. For example to bind to the key sequence tb use:

xnoremap tb :<c-u>call OrmoluBlock()<CR>

If you see quirky behavior using TypeApplications extensions with the code being formatted into invalid Haskell, you probably need to enable -XTypeApplications globally because it is set in your global cabal file per this issue.

let g:ormolu_options=["-o -XTypeApplications"]

To manually install the formatter on a specific file extension invoke RunOrmolu() as a BufWritePre hook.

autocmd BufWritePre *.hs :call RunOrmolu()

To run formatting inside an unsaved buffer as a scratchpad, set your buffer's filetype to haskell and then invoke any of the formatter commands (i.e. :call RunOrmolu()) or bind it key sequence as above.

set filetype=haskell

License

MIT License Copyright (c) 2019-2020, Stephen Diehl

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].