All Projects → kdheepak → JuliaFormatter.vim

kdheepak / JuliaFormatter.vim

Licence: MIT license
A (N)Vim plugin for formatting Julia code using JuliaFormatter.jl.

Programming Languages

Vim Script
2826 projects
julia
2034 projects
lua
6591 projects

Projects that are alternatives of or similar to JuliaFormatter.vim

dotfiles
My NixOS configuration featuring awesome and neovim
Stars: ✭ 40 (-34.43%)
Mutual labels:  nvim
nvim-config
My neovim config
Stars: ✭ 63 (+3.28%)
Mutual labels:  nvim
py lsp.nvim
Lsp Plugin for working with Python virtual environments
Stars: ✭ 58 (-4.92%)
Mutual labels:  nvim
taskrunner.nvim
🏃 Runs Gulp/Gruntfiles in terminal splits
Stars: ✭ 13 (-78.69%)
Mutual labels:  nvim
lsp spinner.nvim
neovim plugin to retrieve the name of the running LSP client(s) and display a spinner when there are wip job
Stars: ✭ 23 (-62.3%)
Mutual labels:  nvim
vscode.nvim
Neovim/Vim color scheme inspired by Dark+ and Light+ theme in Visual Studio Code
Stars: ✭ 362 (+493.44%)
Mutual labels:  nvim
Dotfiles
using vim
Stars: ✭ 245 (+301.64%)
Mutual labels:  nvim
modes.nvim
Prismatic line decorations for the adventurous vim user
Stars: ✭ 299 (+390.16%)
Mutual labels:  nvim
impromptu.nvim
Create prompts fast and easy
Stars: ✭ 39 (-36.07%)
Mutual labels:  nvim
nvim
Structure, documented, super fast neovim configuration. 可能是翻斗花园最好用的 neovim 配置[^1]。
Stars: ✭ 223 (+265.57%)
Mutual labels:  nvim
qf helper.nvim
A collection of improvements for the quickfix buffer
Stars: ✭ 70 (+14.75%)
Mutual labels:  nvim
nvim-fennel-lsp-conjure-as-clojure-ide
Basic config to transform your NVIM in a powerful Clojure IDE using fennel, clojure-lsp and conjure.
Stars: ✭ 144 (+136.07%)
Mutual labels:  nvim
nvim
No description or website provided.
Stars: ✭ 80 (+31.15%)
Mutual labels:  nvim
my-neovim-configurations
Some vim plugs on neovim and its show on MacOS
Stars: ✭ 16 (-73.77%)
Mutual labels:  nvim
lvim
🧑‍🚀 Bloated LunarVim 🚀
Stars: ✭ 317 (+419.67%)
Mutual labels:  nvim
Coc.nvim
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Stars: ✭ 18,268 (+29847.54%)
Mutual labels:  nvim
lsp-command
Command interface for neovim LSP
Stars: ✭ 48 (-21.31%)
Mutual labels:  nvim
dash.nvim
Script runner for quick iteration. Bring your scripting to the next level.
Stars: ✭ 37 (-39.34%)
Mutual labels:  nvim
NVelox
Low level Neovim library.
Stars: ✭ 20 (-67.21%)
Mutual labels:  nvim
coc-java-debug
An extension for coc.nvim to enable Java debugging via jdt.ls
Stars: ✭ 92 (+50.82%)
Mutual labels:  nvim

JuliaFormatter.vim

Plugin for formatting Julia code in (n)vim using JuliaFormatter.jl.

Note: LanguageServer.jl now supports JuliaFormatter.jl, so you may not want to use this if you already are using lsp with vim/neovim.

Install

Use any plugin manager:

vim-plug

Plug 'kdheepak/JuliaFormatter.vim'

dein.vim

call dein#add('kdheepak/JuliaFormatter.vim')

Vundle.vim

Plugin 'kdheepak/JuliaFormatter.vim'

Usage

Open any Julia file, type : to open the command prompt and type the following:

" format full file
:JuliaFormatterFormat
" format last/current selection
:'<,'>JuliaFormatterFormat
" format from line 5 to line 15 inclusive
:5,15JuliaFormatterFormat

You can remap this to a keyboard shortcut as well.

" normal mode mapping
nnoremap <localleader>jf :JuliaFormatterFormat<CR>
" visual mode mapping
vnoremap <localleader>jf :JuliaFormatterFormat<CR>

The (n)vim documentation recommends using <localleader> for a filetype plugin, but feel free to use <leader> or <localleader> for this remap. In (n)vim, both <leader> and <localleader> are set to the \ key by default.

Feel free to open an issue for debugging a problem, questions or feature requests.

For debugging, the following is useful to check.

:JuliaFormatterEchoCmd

You can access the JuliaFormatter server log file by running the following:

:JuliaFormatterLog

Finally, you can run JuliaFormatterUpdate to run julia --project=/path/to/vim_plugin/ -e "using Pkg; Pkg.update()"

:JuliaFormatterUpdate

Note that this repository has loose compat bounds for JuliaFormatter.jl or PackageCompiler.jl. This will most likely result in the latest version of JuliaFormatter.jl and PackageCompiler.jl being installed. If this plugin doesn't work with the latest versions of these packages, please open an issue. Older versions are supported on a best effort basis.

Options

Setting Format Options

Click to expand!

To modify the formatting options can be modified by setting g:JuliaFormatter_options in your vimrc. An example of this is:

let g:JuliaFormatter_options = {
        \ 'indent'                    : 4,
        \ 'margin'                    : 92,
        \ 'always_for_in'             : v:false,
        \ 'whitespace_typedefs'       : v:false,
        \ 'whitespace_ops_in_indices' : v:true,
        \ }

This translates to a call to:

JuliaFormatter.format_text(vim_text_selection_or_buffer, indent = 4, margin = 92; always_for_in = true, whitespace_typedef = false, whitespace_ops_in_indices = true)

See full list of options over on the JuliaFormatter API documentation.

Compatibility with BlueStyle and YASStyle

Click to expand!

JuliaFormatter.vim enables compatibility with BlueStyle and YAS.

Here is how to configure (n)vim for BlueStyle or YAS:

  1. Install JuliaFormatter.vim

  2. Add the following to your vimrc to follow the BlueStyle standard:

    let g:JuliaFormatter_options = {
            \ 'style' : 'blue',
            \ }

    This translates to a call to:

    style = BlueStyle()
    JuliaFormatter.format_text(vim_text_selection_or_buffer, style = style)

    OR

    Add the following to your vimrc to follow the YAS standard:

    let g:JuliaFormatter_options = {
            \ 'style' : 'yas',
            \ }

    This translates to a call to:

    style = YASStyle()
    JuliaFormatter.format_text(vim_text_selection_or_buffer, style = style)
  3. (Optional) Create a file in the path ~/.vim/after/ftplugin/julia.vim and add to the julia.vim file the following:

    " ~/.vim/after/ftplugin/julia.vim
    setlocal expandtab       " Replace tabs with spaces.
    setlocal textwidth=92    " Limit lines according to Julia's CONTRIBUTING guidelines.
    setlocal colorcolumn+=1  " Highlight first column beyond the line limit.

Support .JuliaFormatter.toml configuration

Click to expand!

When :JuliaFormatterFormat is called, it will look for .JuliaFormatter.toml in the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found. When found, the configurations in the file will overwrite the options provided by g:JuliaFormatter_options.

See https://domluna.github.io/JuliaFormatter.jl/stable/config/ for more information.

Precompiling JuliaFormatter using PackageCompiler

Click to expand!

Using a custom system image can speedup the initialization time of the plugin. This can be done using PackageCompiler.jl.

PackageCompiler.jl can be used with JuliaFormatter.vim by running the following:

$ cd /path/to/JuliaFormatter.vim/
$ julia --project scripts/packagecompiler.jl

This will create a Julia sysimage that is stored in /path/to/JuliaFormatter.vim/scripts folder. You can type :echo g:JuliaFormatter_root in (n)vim to find where /path/to/JuliaFormatter.vim/ is. For more information check (n)vim documentation or consult your plugin manager documentation.

Then in your vimrc set:

let g:JuliaFormatter_use_sysimage=1

If you would like to use a sysimage that is located elsewhere, you can do so too. Add the following to your vimrc:

let g:JuliaFormatter_use_sysimage=1
let g:JuliaFormatter_sysimage_path="/path/to/julia_sysimage.so"

Launching the JuliaFormatter server when opening a Julia file

Click to expand!

By default, the JuliaFormatter server is only started the first time you call :JuliaFormatterFormat. This means your first format will be slower than the remaining times for an open session of (n)vim. PackageCompiler.jl compiles JuliaFormatter.jl, JSON.jl and other methods used for formatting Julia code and this significantly speeds up the first call to :JuliaFormatterFormat. Once the server is started, it is waiting for input on stdin and remaining calls will be fast.

Additionally, if you would like, you can start the server when you open a Julia file for the first time instead of when you call :JuliaFormatterFormat for the first time. Just add the following in your vimrc:

let g:JuliaFormatter_always_launch_server=1

Format on save using neovim built in LSP formatting

You'll need https://github.com/mattn/efm-langserver. Add the following to your .vimrc:

require"lspconfig".efm.setup {
    init_options = {documentFormatting = true},
    filetypes = {"julia"},
    settings = {
        rootMarkers = {".git/"},
        languages = {
            julia = {require("juliaformatter").efmConfig}
        }
    }
}

Then you can this to ftplugin/julia.vim:

autocmd BufWritePre *.jl lua vim.lsp.buf.formatting_sync()

This works best if you have and use PackageCompiler to compile JuliaFormatter into a sysimage.

You can run the following to see what process is executed on the command line to format your code:

:lua print(require("juliaformatter").efmConfig)

Troubleshooting

Click to expand!

See MINRC before opening an issue.

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].