Coder Social home page Coder Social logo

aserebryakov / filestyle Goto Github PK

View Code? Open in Web Editor NEW
30.0 6.0 5.0 85 KB

filestyle is a Vim plugin that highlights unwanted whitespace and characters.

Home Page: http://www.vim.org/scripts/script.php?script_id=5065

License: Apache License 2.0

Vim Script 100.00%
viml vim-plugins vim-plugin vim-scripts clean-code

filestyle's Introduction

filestyle

filestyle is a Vim plugin that highlights unwanted whitespace and characters.

Highlights include:

  • Trailing spaces
  • Tabs or spaces depending on 'expandtab'
  • Lines longer than 'textwidth'
  • Control characters

filestyle also lets you fix these issues (experimental).

Examples

Example 1

Example 2

Example 3

Installation

Step 1: Install filestyle

Pathogen
$ cd ~/.vim/bundle
$ git clone https://github.com/aserebryakov/filestyle.git
NeoBundle
NeoBundle 'aserebryakov/filestyle'
Without plugin manager

Clone or download this repository and copy its contents to your ~/.vim/ directory.

Step 2: Check your colorscheme (Vim only)

When using Vim (not gVim), make sure your colorscheme explicitly defines ctermbg in a Normal highlight group as it is required for the ignore patterns feature. For example:

hi Normal ctermbg=15

Usage

filestyle automatically checks each opened file.

Commands
  • :FileStyleEnable - enable plugin globally
  • :FileStyleDisable - disable plugin globally
  • :FileStyleToggle - toggle enable/disable plugin globally
  • :FileStyleActivate - enable plugin for current buffer
  • :FileStyleDeactivate - disable plugin for current buffer
  • :FileStyleCheck - check current buffer
  • :FileStyleFix - fix style errors
Highlighting rules
  1. If 'expandtab' is set, highlight tabs (RED), if not, highlight spaces at the beginning of a line (YELLOW).
  2. Highlight trailing spaces (CYAN)
  3. Highlight line parts that exceed 'textwidth' (INVERT)
  4. Highlight control characters (BLUE)
FileStyleFix rules
  1. Remove control characters
  2. Remove trailing spaces
  3. If 'expandtab' is set, replace tabs with spaces, if not, replace spaces at the beginning of a line with tabs
Ignore file types

By default, filestyle checks all file types. To ignore a file type, for example text, add the following line to your .vimrc:

let g:filestyle_ignore = ['text']
Ignore patterns

filestyle allows you to specify patterns that should be ignored. To ignore a pattern, for example quoted lines starting with >, add the following line to your .vimrc:

let g:filestyle_ignore_patterns = ['^\(> \?\)\+$']
Change highlight groups

filestyle currently uses these highlight groups:

FileStyleTabsError
FileStyleTrailingSpacesError
FileStyleSpacesError
FileStyleControlCharacter
FileStyleTooLongLine
FileStyleIgnoredPattern

Note that FileStyleIgnoredPattern is only used in gVim.

You can change a highlight group in your .vimrc or color scheme like this:

highlight FileStyleTabsError ctermbg=3 guibg=Yellow
Known issues
  • filestyle cannot detect 'textwidth' changes. If you change 'textwidth', execute :FileStyleCheck to ensure the new width is used for highlighting long lines.

  • Error E315 is be thrown by Vim in case of 'splitbelow' option is set when 'help' command is called

Contribution

Source code and issues are hosted on GitHub:

https://github.com/aserebryakov/filestyle

License

Apache License, Version 2.0

Changelog

1.2.0

  • Added FileStyleToggle command
  • Fixed the error if default colorscheme is used

1.1.2

  • Fixed error messages when Vim is started in a narrow terminal
  • Fixed tag and version number in help file

1.1.1

  • Fixed cursor positioning after FileStyleFix call

1.1.0

  • Added support for user-defined highlight groups
  • Fixed issue with tabs switching in INSERT mode

1.0.0

  • Implemented ignored patterns
  • Removed highlighting of trailing spaces in current line when in Insert mode
  • Improved order of highlights

0.7.1

  • Fixed issue with highlighting after colorscheme change

0.7.0

  • Implemented style errors fixing (experimental)
  • Added commands to enable/disable filestyle globally
  • Fixed highlighting of the EOL
  • Fixed disabling filestyle for specific buffers

0.6.1

  • Fixed compatibility with other plugins when Vundle is used

0.6.0

  • Added option to ignore certain file types
  • Changed :FileStyleDeactivate to turn off highlighting in all windows of the current buffer
  • Added highlighting of control characters

0.5.2

  • Fixed the undefined variable filestyle_active error

0.5.1

  • Added commands to enable/disable filestyle
  • Fixed several bugs
  • Changed highlighting to use distinct colors for different violations of buffer settings

0.5.0

  • Added highlighting of trailing spaces
  • Added highlighting of incorrect indentation

Credits

  • Alexander Serebryakov, original author (GitHub)
  • Markus Weimar (GitHub)

filestyle's People

Contributors

alx741 avatar aserebryakov avatar kovetskiy avatar markus00000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

filestyle's Issues

[BUG]: Errors when starting Vim in a narrow terminal

Starting Vim in a narrow terminal with fewer than 40 columns produces these messages at startup and while editing:

FileStyle: ctermbg parameter should be defined explicitly
Press ENTER or type command to continue

Error detected while processing functio
n FileStyleActivate..FileStyleCheck..Fi
leStyleClearIgnoredPatters..FileStyleHi
ghlightPattern:
line    7:
E28: No such highlight group name: File
StyleIgnoredPattern
Error detected while processing functio
n FileStyleActivate..FileStyleCheck..Fi
leStyleClearBufferMatches:
line    3:
E802: Invalid ID: -1 (must be greater t
han or equal to 1)
Press ENTER or type command to continue

Error detected while processing functio
n FileStyleActivate..FileStyleCheck..Fi
leStyleClearIgnoredPatters..FileStyleHi
ghlightPattern:
line    7:
E28: No such highlight group name: File
StyleIgnoredPattern
Press ENTER or type command to continue

Find a better solution for issue #6

Current solution l of the issue 'Spaces and tabs are highlighed for help files #6' looks like a workaround of the issue. Probably, there is another one better solution.

Automatic styling errors fixing when file is opened

Functionality

When file is opened and style is checked, user should be asked if he wants to cleanup the file.

Additional Requirements

  • Add an option to enable / disable this feature
  • Feature should be disabled by default

Function [...] already exists

I'm using vundle and after installing any other plugin i got a messages:

Error detected while processing /home/vxw/repos/filestyle/plugin/filestyle.vim:
line   54:
E122: Function FileStyleActivate already exists, add ! to replace it
line   65:
E122: Function FileStyleDeactivate already exists, add ! to replace it
line   73:
E122: Function FileStyleClearFile already exists, add ! to replace it
line   82:
E122: Function FileStyleCheckFiletype already exists, add ! to replace it
line   88:
E122: Function FileStyleHighlightPattern already exists, add ! to replace it
line  101:
E122: Function FileStyleExpandtabCheck already exists, add ! to replace it
line  109:
E122: Function FileStyleTrailingSpaces already exists, add ! to replace it
line  119:
E122: Function FileStyleLongLines already exists, add ! to replace it
line  127:
E122: Function FileStyleControlCharacters already exists, add ! to replace it
line  139:
E122: Function FileStyleCheck already exists, add ! to replace it

Disable FileStyle in Quickfix

I've tried pretty much everything, but I cannot get FileStyleDeactivate to work when a QuickFix window is populated. The result is compiler errors being highlighted because their lines are too long. This isn't a massive issue, but it's certainly a nuisance. Would it be possible to have an option for FileStyle to not act on QuickFix or nonmodifiable buffers in general?

[BUG:] E803 error when opening a go file using Unite

Should be able to duplicate this by opening the tcp_socket.go file in github.com/docker/docker/

Here is the full error message:

[unite.vim] function FileStyleActivate..FileStyleCheck..FileStyleClearBufferMatches, line 3
[unite.vim] Vim(call):E803: ID not found: 10
[unite.vim] Error occurred while executing "open" action!

Make \t\t\t\s\s indent schema possible

Hi!
In some projects codestyle allows to use several spaces after tabs for indention.
So it would be good if there would be possibility to configure filestyle to accept it.

As far as I can see it there can be two modes in it.

  1. spaces after tabs (or some number of it) are totally legal. So user can enumerate numbers of spaces that are acceptable
    2 for accept \t*\s\s
    1,2,3 for accept \t*\s*{1,3}
    (regexp are in perl-style sorry)

The last one I've solved with

let g:filestyle_ignore_patterns = ['^\t* \{1,3}\S']

but it take me a while, i am not good with vim regexp. Better to have it in the code of plugin or at least in documentation...

  1. Second mode is when spaces after tabs are acceptable, but should draw an attention.

As far as I can see this mode should be configured in the same way, and only spaces after \t* should be highlighted in some warning highlight background (i.e. gray: all is ok, but please pay attention)

This mode will suit me better then the first one, but I am not able to implement using tools that are described in plugin docs.

Normal colorscheme in vim problems

Hi!
I am new to vim and I am using it in linux terminal.

This colorscheme issue gave me some problems...

First it would be good to change

hi Normal ctermbg=15

in documentaion to

highlight Normal ctermbg=15

so it would be possible just to google it. Googling for "hi" is pointless...

Second issue, I am using some black background color scheme, that goes in debian by default.

When I did "hi Normal ctermbg=15" background changed to white, it was awful.

I tried "hi Normal ctermbg=0" it made background black, but changed colors of the text.

Trying things blindly I came to "hi Normal ctermbg=16" that gives black background and keeps text colors as they were. But I do not understand why.

It would be nice to have more explanation in the doc concerning this Normal colorscheme issue. Or may be not explanations but some ready recipes for new users like "use "hi Normal ctermbg=16" if your color scheme is black", if it is too complex to explain. There should not be many usual cases, so most of them can be covered.

[FEATURE]: Style fixing

Requirements:

  1. User should be able to fix style errors with a command
  2. Trailing spaces should be removed
  3. Tabs should be replaced by spaces dependently on expandtab option set
  4. Spaces in the beginning of the line should be replaces by tabs if noexpandtab option is set
  5. In case of control symbols in the file, user should be asked if they will be removed

[BUG]: Error E315 if 'splitbelow' option is set.

When using the splitbelow option, I get strange Vim internal errors (E315), for each line, when opening a help topic.

How to reproduce (minimal vimrc - I use vim-plug as plugin manager):

set nocompatible

filetype off
call plug#begin('~/.vim/plugged')
    Plug 'aserebryakov/filestyle'
call plug#end()

filetype plugin indent on
syntax on

set splitbelow

The errors look like:

:h syntax.txt
E315: ml_get: invalid lnum: 5319
E315: ml_get: invalid lnum: 5318
...
E315: ml_get: invalid lnum: 1

I suspect the wincmd w commands are to blame, but I don't know how to change them.

Thanks for the plugin!

[FEATURE]: Do not highlight trailing spaces in INSERT mode

User scenario

  1. Switch to INSERT mode
  2. Type a sentence

Current behavior

Each time when user puts a space after word and before starting a new word, trailing space is highlighted.

Expected behavior

Trailing space is not highlighted in current line while in INSERT mode, but highlighted immediately after exiting from INSERT mode

Error first time open vim after downloading filestyle

After I download filestyle to my vim folder, when I open a file in Vim, this error is raised:

FileStyle: ctermbg parameter should be defined explicitly. Ignored patterns are disabled

Error detected while processing VimEnter Autocommands for "*"..function FileStyleActivate[3]..FileStyleCheck[13]..FileStyleClearBufferMatches:
line    3:
E803: ID not found: 7
Press ENTER or type command to continue
Error detected while processing VimEnter Autocommands for "*"..function FileStyleActivate[3]..FileStyleCheck[13]..FileStyleClearBufferMatches:
line    3:
E803: ID not found: 8
Press ENTER or type command to continue
Error detected while processing VimEnter Autocommands for "*"..function FileStyleActivate[3]..FileStyleCheck[13]..FileStyleClearBufferMatches:
line    3:
E803: ID not found: 9
Press ENTER or type command to continue

\t\t\s\t\t is highligted only till the first space

I am using filstyle without expandtab

I found out that if I mix spaces and tabs in indention then this mix will be highlighted only till the first space in that mixture. The rest of the empty space would be black.

I do not see it is as a good behavior, as if i do \s\t\t\t\t\t only one character will be highlighted so it would be a bit difficult to notice the problem.

The second issue, if somebody will write \s\t\s\t\s\t\s\t\s\t I would not be able to see the whole problem form the start, I will see next problematic space only after deleting the previous one.

So my suggestion is the following: If there is a problem is indention the whole indention is highlighted as yellow. And all problematic characters are highlighted in red. It should work in this way both with expandtab and without. Expandtab just changes what characters are considered wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.