Skip to content

IDE: vim

Justin Searls edited this page Apr 21, 2023 · 12 revisions

vim-LSP

The recommended method for running standardrb within vim is with vim-lsp.

First install vim-lsp:

$ git clone git@github.com:prabirshrestha/vim-lsp.git $HOME/.vim/pack/github/opt/vim-lsp

Edit your vimrc to first tell Vim to load the vim-lsp plugin:

# Tell Vim to find vim-lsp
packadd vim-lsp

Then, also in your vimrc, teach vim-lsp to execute standardrb for Ruby files:

# Use standard if available
if executable('standardrb')
  au User lsp_setup call lsp#register_server({
        \ 'name': 'standardrb',
        \ 'cmd': ['standardrb', '--lsp'],
        \ 'allowlist': ['ruby'],
        \ })
endif

ALE

To set Standard as your only linter and fixer for Ruby files and thereby preventing conflicts with RuboCop, add these lines to your .vimrc file:

let g:ale_linters = {'ruby': ['standardrb']}
let g:ale_fixers = {'ruby': ['standardrb']}

For automatically fixing on save, add this to your .vimrc:

let g:ale_fix_on_save = 1

vim-ruby

It is quite common for rubyists to use vim-ruby for ruby-aware syntax highlighting and indentation. However, vim-ruby's default indentation conflicts with standardrb. The following will configure vim-ruby to use the same indentation style as standardrb:

let g:ruby_indent_assignment_style = 'variable'
let g:ruby_indent_hanging_elements = 0

see also: vim-ruby indentation docs

Clone this wiki locally