alexkornitzer / vim-lessmess

Remove white-space mess from files in ViM :coffee: :coffee: :coffee:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

 ██╗     ███████╗███████╗███████╗███╗   ███╗███████╗███████╗███████╗
 ██║     ██╔════╝██╔════╝██╔════╝████╗ ████║██╔════╝██╔════╝██╔════╝
 ██║     █████╗  ███████╗███████╗██╔████╔██║█████╗  ███████╗███████╗
 ██║     ██╔══╝  ╚════██║╚════██║██║╚██╔╝██║██╔══╝  ╚════██║╚════██║
 ███████╗███████╗███████║███████║██║ ╚═╝ ██║███████╗███████║███████║
 ╚══════╝╚══════╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚══════╝╚══════╝

Lessmess: ViM even better whitespaces Plugin

Build Status

Features

This plugin is capable of doing the following things for you:

  • Remove trailing white-spaces at the end of a line;
  • Fix mixed-indent, in other words, replace all sequences of 'Tab' character with new string of white-space;
  • Remove empty lines at the end of the file;

By default the plugin does all of the above when you save a file, but this can be disabled to be able to execute clean-up on demand only. Additionally, The plugin can be configuration to request user confirmation before removing white-spaces.

Instalation

  1. (natively) Using ViM 8 packages

First, create a directory structure representing a plugin-group, say whitespace, as follows:

mkdir -p ~/.vim/pack/whitespace/start/

Next, clone (or alternatively, download the zip, and unzip) the plugins you want to install inside the start directory:

cd ~/.vim/pack/whitespace/start/
git clone https://github.com/mboughaba/vim-lessmess.git
git clone https://github.com/mboughaba/vim-lessmess.git
  1. Using Vundle

First, declare the plugin in your .vimrc

Plugin 'mboughaba/vim-lessmess'

Then run plugin install command

:PluginInstall
  1. Using Plug

First, declare the plug in your .vimrc

Plug 'mboughaba/vim-lessmess'

Then run plug install command

:PlugInstall

Motivation

Every ViM user has a custom configuration to remove trailing white-spaces, mine was autocmd BufWritePre * :%s/\s\+$//e Such a trivial task isn't it? Well the idea here is all about moving that custom logic to its own plugin without having an impact on performance.

Keeping it stupid simple. I had the code around in my .vimrc and I decided to make a plugin out of it. This is fully tested and blazing fast but if you don't mind white-spaces in your files 👽 this is the best time to navigate away 🚀

Usage

Out of the box, this plugin will clean trailing white-spaces, fix mixed-indents and remove empty lines at the end of a file when the file is being saved. In more technical details, there are two important functions LessmessExecute and LessmessDisplayToggle.

Automagically 💫 remove all annoying white-spaces ✔️

White-spaces removal onsave is enabled by default. Just save the buffer and the file is clean.

Manually remove all annoying white-spaces

First, to disable lessmess onsave make sure to include the configuration below in your .vimrc

let g:enable_lessmess_onsave = 0

To remove ondemand trailing white-spaces, fix mixed-indents and remove newlines at the end of file all at once, call the following command:

LessmessExecute

Simple white-spaces highlighting

I personally don't see a need of white-space highlighting, as long as I am confident they will be removed when I save. Nevertheless, to toggle highlighting of hidden characters, use command below.

LessmessDisplayToggle

This is simply calling vim native toggle list, I highly believe that syntax highlighting for white-spaces is a bit overkill in many cases so why not just use something as simple as ViM built-in list.

Configuration

  1. To Enable/disable Lessmess
LessmessToggle
  1. Plugin can be disabled per buffer. An example would disabling white-space trimming for all vader test files
"
" Lessmess disable by FileType
"
aug disable_lessmess
    au!
    au FileType vader let b:lessmess_disable_buffer = 1
aug end
  1. To completely disable the plugin, setting below can be added to .vimrc
let g:disable_lessmess = 1

Handy tool 🔧

When Lessmess is disabled, white-spaces can be removed by calling force execute 🔨:

LessmessForceExecute

Checking plugin status

To check status of the plugin one should call

LessmessStatus

Advanced configuration

  1. Lessmess can be configured to request user's confirmation before removing white-spaces. To enable this feature, following configuration need to be added to the user's .vimrc
let g:confirm_whitespace_removal = 1

This feature is disabled by default.

Before execution, the plugin will ask something similar to: White-spaces found in file, remove them? y/N: , user then decides to apply y or skip N (default) white-space removal. Confirmation is done once per buffer, this means that the plugin will remember user's choice for a given buffer.

Running tests

check the setup in the test folder.

test/vader/run

Self promotion

Why this one and not the other two trailing white-spaces removal plugins

  1. This is fully autoloaded, slowing down your ViM startup time was not an option
  2. This is designed with performance in mind. The plugin doesn't do live updates, it does the heavy lifting when ViM is idle.
    1. Making use of Vim jobs is in the pipe.
  3. Absolutely no configuration is required to get started. Everything follows the KISS principle
  4. This plugin is fully unit tested using Vader
  5. This running on Travis CI
  6. This is actively maintained
  7. More features can be added easily on top of the base we have so far

👋 Hey if you like the plugin and find it useful hit

ezoic increase your site revenue

About

Remove white-space mess from files in ViM :coffee: :coffee: :coffee:

License:MIT License


Languages

Language:Vim script 98.7%Language:Shell 1.3%