Remove auto format and autofix from ZLS COMPLETELY (with nvim kickstart)

2 min read 04-10-2024
Remove auto format and autofix from ZLS COMPLETELY (with nvim kickstart)


Say Goodbye to Auto-Formatting: Disabling ZLS's Autofix in Neovim Kickstart

Tired of ZLS's automatic formatting and auto-fixing disrupting your workflow? Want complete control over your code's appearance? This article will guide you through disabling these features in your Neovim Kickstart setup, giving you the freedom to format your code exactly how you like it.

The Problem

ZLS, a powerful language server for Zsh, comes with built-in features like auto-formatting and auto-fixing that aim to improve code readability. However, these features can sometimes be intrusive, interfering with your editing process and introducing unwanted changes. If you prefer to control formatting manually or use your preferred formatter, disabling ZLS's autofix features becomes essential.

The Solution: Disabling Auto-Formatting and Auto-Fixing in Neovim Kickstart

Here's a step-by-step guide on how to disable ZLS's auto-formatting and auto-fixing in your Neovim Kickstart configuration:

  1. Locate the lua/user/lspconfig.lua file: This file is responsible for configuring your LSP servers, including ZLS.

  2. Find the zls configuration section: Within the lua/user/lspconfig.lua file, locate the zls configuration block. This block typically looks like this:

    require('lspconfig').zls.setup {
      -- Other settings for ZLS
    }
    
  3. Disable formatting and auto-fixing: Add the following options to your ZLS configuration to disable formatting and auto-fixing:

    require('lspconfig').zls.setup {
      -- Other settings for ZLS
      format_text = false,
      auto_format_on_save = false,
      auto_fix_on_save = false,
      command_completion = false,
    }
    
    • format_text: Disables ZLS's built-in formatting capabilities.
    • auto_format_on_save: Prevents ZLS from automatically formatting your code upon saving.
    • auto_fix_on_save: Disables ZLS's automatic code fixing on save.
    • command_completion: Disables the command completion feature. This might be helpful to avoid ZLS's interference with your shell completion setup.
  4. Reload your Neovim configuration: After making these changes, restart Neovim or reload the configuration to apply the settings.

Additional Tips and Considerations

  • Use a dedicated formatter: Consider using a dedicated Zsh formatter like zsh-syntax-highlighting for a more customizable and refined formatting experience.
  • Customize linting: ZLS offers advanced linting capabilities. Explore ZLS's configuration options to tailor linting rules to your specific needs.
  • Control over your code: By disabling ZLS's auto-formatting and auto-fixing, you gain complete control over your code's appearance, ensuring it aligns with your preferences and coding style.

Conclusion

Disabling ZLS's auto-formatting and auto-fixing in your Neovim Kickstart setup allows you to take full control over your Zsh code formatting. This approach offers a more refined and customizable editing experience, aligning with your preferences and workflow. Remember to explore ZLS's configuration options to tailor your development environment for optimal productivity and code quality.