vimsyntasticvim-powerline

Vim Powerline with Syntastic segment


How do I add a syntastic segment to the powerline footer for Vim? (the new powerline, not vim-powerline) Syntastic docs only say how to add it to the standard Vim footer and I couldn't find how to add it in the powerline docs.


Solution

  • Most of these instruction come from this pull request (451) for powerline.

    This pull request adds a syntactic segment to powerline. Since the segment isn't merged into the main powerline tree you need to preform the patches by hand. Thankfully you only need to modify three files. (+ means add the line/ - mean remove line). Look at the pull request for a colored diff.

    File: powerline/config_files/colorschemes/vim/default.json (Line 28)

         "line_current_symbol": { "fg": "gray1", "bg": "gray10" },
         "virtcol_current_gradient": { "fg": "dark_GREEN_Orange_red", "bg": "gray10" },
         "col_current": { "fg": "gray6", "bg": "gray10" },
    -    "modified_buffers": { "fg": "brightyellow", "bg": "gray2" }
    +    "modified_buffers": { "fg": "brightyellow", "bg": "gray2" },
    +    "syntastic_segment": { "fg": "brightestred", "bg": "gray2", "attr": ["bold"] }
       },
       "mode_translations": {
         "nc": {
    

    File: powerline/config_files/colorschemes/vim/default.json (Line 68)

           "groups": {
             "mode": { "fg": "darkestcyan", "bg": "white", "attr": ["bold"] },
             "background:divider": { "fg": "darkcyan", "bg": "darkestblue" },
    -        "branch:divider": { "fg": "darkcyan", "bg": "darkblue" }
    +        "branch:divider": { "fg": "darkcyan", "bg": "darkblue" },
    +        "syntastic_segment": { "fg": "white", "bg": "darkestblue", "attr": ["bold"] }
           }
         },
         "v": {
    

    File: powerline/config_files/colorschemes/vim/solarized.json (Line 27)

         "line_current":             { "fg": "gray13", "bg": "lightyellow", "attr": ["bold"] },
         "line_current_symbol":      { "fg": "gray13", "bg": "lightyellow" },
         "virtcol_current_gradient": { "fg": "GREEN_Orange_red", "bg": "gray10" },
    -    "col_current":              { "fg": "azure4", "bg": "lightyellow" }
    +    "col_current":              { "fg": "azure4", "bg": "lightyellow" },
    +    "syntastic_segment":        { "fg": "red", "bg": "royalblue5", "attr": ["bold"] }
       },
       "mode_translations": {
         "nc": {
    

    File: powerline/config_files/colorschemes/vim/solarized.json (Line 65)

             "line_percent_gradient":  { "fg": "oldlace", "bg": "gray61" },
             "line_current":           { "fg": "gray13", "bg": "oldlace", "attr": ["bold"] },
             "line_current_symbol":    { "fg": "gray13", "bg": "oldlace" },
    -        "col_current":            { "fg": "azure4", "bg": "oldlace" }
    +        "col_current":            { "fg": "azure4", "bg": "oldlace" },
    +        "syntastic_segment":      { "fg": "lightyellow", "bg": "darkgreencopper", "attr": ["bold"] }
           }
         },
         "v": {
    

    File: powerline/segments/vim.py (Line 23)

       'expand': vim_get_func('expand', rettype=str),
       'bufnr': vim_get_func('bufnr', rettype=int),
       'line2byte': vim_get_func('line2byte', rettype=int),
    +  'exists': vim_get_func('exists', rettype=int),
     }
    
     vim_modes = {
    

    At the end of powerline/segments/vim.py add the following function. (Make sure you use tabs to indent the function. You are modifying a python file indentation matters)

    @window_cached
    def syntastic_segment(pl):
        '''Return the syntastic statusline flag
        '''
        if int(vim_funcs['exists']('*SyntasticStatuslineFlag')) > 0:
            syntastic_flag_func = vim_get_func('SyntasticStatuslineFlag', rettype=str)
            return [{
                'contents': str(syntastic_flag_func()),
            }]
        else:
            return None
    

    After all these changes are made you need to now turn on the segment. One way to do this is to edit the config file ~/.config/powerline/themes/vim/default.json

    In the section segments: place the following in either the right or the left sections.

    {
        "name": "syntastic_segment",
        "before": " "
    },
    

    After all of these changes you should now be able to see the syntastic error output on the power line segment.


    Troubleshooting: