Git Product home page Git Product logo

context.vim's Introduction

context.vim

A Vim plugin that shows the context of the currently visible buffer contents. It's supposed to work on a wide range of file types, but is probably most useful when looking at source code files. In most programming languages this context will show you which function you're looking at, and within that function which loops or conditions are surrounding the visible code.

Here's an animation which shows it in action. See below for an explanation.

Motivation

Do you ever find yourself looking at code with long functions or deeply nested loops and conditions? Do you ever lose your place and start scrolling in your buffer to see where you are? This plugin aims to always show you that context for your currently active buffer so you always know your place.

Example

Here's an screenshot showing parts of eval.c in the Vim source code:

At the bottom you see the actual buffer. At the top you see a popup window used by context.vim to show the context of that code. So here we are looking at some code within the echo_string function. And within that function we are currently handling the case where tv->v_type is VAR_LIST and so on.

In the animation above you can see how the context changes as we scroll through this function.

How it works

This plugin should work out of the box for most file types. It's based on indentation and some regular expressions.

Below is an illustration of how it works: Start at the grey box in the bottom left corner. It shows the original visible buffer content as you would see it without this plugin. Above the box we can see what's usually hidden, the file contents above the visible area. You'd need to scroll up to see it.

This plugin scans upwards through these hidden lines to collect the context. Every time it hits a line with a lower indentation than the last one it will add it to the context. There is also some logic to add lines with same indentation to the context in some cases. For example it adds the else line which belongs to the first { and also the else if and if lines. So you know exactly what this else case is about. All lines which are part of the context in this example are displayed with color while the remaining lines are greyed out.

In the top right corner we see again all these lines which make up the context. Below is a condensed version where some lines were joined. We show ellipsis (···) between the joined parts if there was text between them in the original buffer. So this tells you that there was code within the else if block, but not between the else if condition and the { line below it.

In the bottom right corner we see the final result: The context is displayed in a preview window above the original buffer.

Installation

Plugin Manager Command
Vim-plug Plug 'wellle/context.vim'
Vundle Bundle 'wellle/context.vim'
NeoBundle NeoBundle 'wellle/context.vim'
Dein call dein#add('wellle/context.vim')

Settings

This plugin is supposed to work out of the box. But there are some variables which can be set to different values to tweak the behavior. Below we show each of those together with their default value for reference. Copy/paste these lines to your vimrc and change the values to your liking.

If you feel like one of these default settings are bad in some way or could be improved to create more useful contexts in some file types, please open an issue and let me know. Also if you feel like any of these settings would need to be settable on a per buffer/per file type basis.

let g:context_enabled = 1

This plugin is enabled by default. Set this variable to 0 to disable it. You can then use :ContextEnable or :ContextToggle to enable it on demand.

let g:context_filetype_blacklist = []

By default, no filetypes will be ignored for the context buffer to appear. If you wish to blacklist a specific filetype, add the name of the filetype to this list.

let g:context_add_mappings = 1

By default we create some mappings to update the context on all Vim commands which scroll the buffer. Set this variable to 0 to disable that. See below on how to customize these mappings if needed.

Note: Ideally there would be an auto command event for when the buffer had scrolled, but unfortunately that doesn't exist. vim#776

let g:context_add_autocmds = 1

By default we set up some auto commands to update the context every time the buffer might have scrolled. Most notably on CursorMoved. Set this variable to 0 to disable that. See below on how to customize these auto commands if needed.

let g:context_presenter = <depends>

This variable can be used to control how the context is presented. The default logic works like this: If you're running a Neovim version which supports floating windows, use them ('nvim-float'). If you're running a Vim version which supports popup windows, use them ('vim-popup'). Otherwise use a preview window ('preview'). So for example you could force the usage of preview windows by setting g:context_presenter to 'preview'. It is recommended to stick to the default though (by not setting this variable) as floating/popup windows should lead to the best experience.

let g:context_max_height = 21

If the context gets bigger than 21 lines, it will only show the first ten, then one line with ellipsis (···) and then the last ten context lines.

let g:context_max_per_indent = 5

If we extend the context on some indent and collect more than five lines, it will only show the first two, ellipsis (···) and then the last two.

Note: This is likely to happen if you have many else if conditions or many case statements within a switch.

let g:context_max_join_parts = 5

If we extend the context on some indent we try to join them. By default we join a context line into the previous line of same indent if the former has no word characters. For example in C-style indentation we would join the { line to the if (condition) line. So in the context it would show up as if (condition) {.

In complex cases there can be a big number of such context lines which we will join together. By default we only show up to 5 such parts.

Note: This can happen if you have long lists of struct literals, so in the context it would look like { ··· }, { ··· }, { ··· }. Set g:context_max_join_parts to 2 or 1 to shorten this to { ··· or just { respectively.

let g:context_ellipsis_char = '·'

By default we use this character (digraph .M) in our ellipsis (···). Change this variable if this character doesn't work for you or if you don't like it.

g:context_border_char = ''

If your Vim/Neovim version supports popup/floating windows we draw a line to separate the context from your buffer context. This character is used to do that.

let g:context_highlight_normal = 'Normal'
let g:context_highlight_border = 'Comment'
let g:context_highlight_tag    = 'Special'

If your Vim/Neovim version supports popup/floating windows we use these highlight groups for the popup window (normal), the border line (border) and the "tag" (<context.vim> at the end of the border line) (tag). By default the popup window uses the same background color as your buffer. For example you could change that to make it more visually distinct by setting g:context_highlight_normal to 'PMenu'.

If you use Vim you can define your own highlight group like highlight MyColor ctermbg=lightblue and set g:context_highlight_normal to 'MyColor'. In Neovim this is currently not supported (see :h 'winhl').

Note: These highlight settings can also be used to hide the tag (let g:context_highlight_tag = '<hide>') or the full border line (let g:context_highlight_border = '<hide>').

let g:context_skip_regex = '^\s*\($\|#\|//\|/\*\|\*\($\|/s\|\/\)\)'

If a buffer line matches this regular expression then it will be fully ignored for context building. By default we skip empty lines, comments and C preprocessor statements.

let g:context_extend_regex = '^\s*\([]{})]\|end\|else\|case\>\|default\>\)'

If a buffer line matches this regular expression, context.vim will extend the context on the current indentation level. So instead of searching upwards for the first line of smaller indent, it will also look for lines with the same indent. For example if we find an else or else if line, we will look upwards for other else if or the initial if line. That way all these conditions will be part of the context so it's more clear of what the current case actually is about. Also by default we extend if the current line starts with any square bracket or curly brace. So for example in a C-style if condition we would extend the { line to include the if line.

let g:context_join_regex = '^\W*$'

If we extended the context on some indent, we will join a line of this indent into the one above if the lower one matches this regular expression. So back in the C-style case where our context contains an if (condition) line and a { line below, they will be merged to if (condition) {. And that is because the { line matched this regular expression. By default we join everything which has no word characters.

TODO: update docs

let g:Context_indent = { line -> [indent(line), indent(line)] }

By default we create the context based on the indentation of the context lines. As we scan through the buffer lines we add lines to the context if they have less indent than the last context line. To get the indentation of a given buffer line we use the indent() function. You can use this setting to use your own function instead. That way you can customize what goes into your context.

The function takes a line number and is supposed to return two numbers. The first one is the level. Smaller level means bigger scope, just like indentation. Make sure to return -1 if an invalid line number gets passed in, like indent() does. The second return value is the indentation used for display. You probably want to keep using indent() for this one.

Here's an example that considers Markdown headers for the context: #45 (Note that you need to change g:context_skip_regex too to make this work)

let g:Context_border_indent = function('indent')

When using popup windows we indent the border line to be aligned with the context base line. You can use this setting to use a different function to control that indent. Similar to g:Context_indent this function also takes a line number and returns an indentation number. For example you can disable that indentation at all to always show a full width border line like this: let g:Context_border_indent = { -> 0 }

Commands

By default they shouldn't be needed, but some command are made available for your customization needs:

:ContextActivate

If you disabled auto commands (see below) you need to activate this plugin by executing this command. By default it's called on the VimEnter auto command.

:ContextEnable

If you let g:context_enabled = 0 to disable it by default or have disabled it with one of the commands below you can use this command to enable it.

:ContextDisable

Use this command to disable the plugin. This also hides the context window. Use :ContextEnable to enable it again later.

:ContextToggle

Use this command to toggle between enabling and disabling this plugin. This is useful in mappings.

:ContextEnableWindow

Similar to :ContextEnable, but only affects the current window.

:ContextDisableWindow

Similar to :ContextDisable, but only affects the current window.

:ContextToggleWindow

Similar to :ContextToggle, but only affects the current window.

:ContextPeek

Use this command to temporarily show the current context, but hide it again on the next cursor movement.

:ContextUpdate

If you disabled auto commands (see below) the context won't be updated automatically. Use this command to update it manually.

Auto commands

This plugin uses auto command to update the context automatically. You can disable that by setting g:context_add_autocmds to 0.

If you want to set up your own auto commands, here are the default ones for reference:

autocmd VimEnter     * ContextActivate
autocmd BufAdd       * call context#update('BufAdd')
autocmd BufEnter     * call context#update('BufEnter')
autocmd CursorMoved  * call context#update('CursorMoved')
autocmd VimResized   * call context#update('VimResized')
autocmd CursorHold   * call context#update('CursorHold')
autocmd User GitGutter call context#update('GitGutter')
autocmd OptionSet number,relativenumber,numberwidth,signcolumn,tabstop,list
            \          call context#update('OptionSet')

if exists('##WinScrolled')
    autocmd WinScrolled * call context#update('WinScrolled')
endif

Note the VimEnter one. When Vim starts this plugin isn't active yet, even if enabled. That is because there are some issues with trying to open a preview window before Vim finished opening all windows for the provided file arguments. So if you disable auto commands you will need to call :ContextActivate in some way to activate this plugin.

Also note how we use the WinScrolled autocommand if it is available.

Mappings

Older versions of Vim and Neovim didn't have the WinScrolled autocommand. For those versions we use some mappings to update the context when the window scrolls. If available we prefer using the autocommand. Additionally we have custom mappings for zt and H to deal with the height of the visible context. If you want to set your own mappings you can disable the default ones by setting g:context_add_mappings to 0.

If you want to create your own mappings, here are the default ones for reference:

if !exists('##WinScrolled')
    nnoremap <silent> <expr> <C-Y> context#util#map('<C-Y>')
    nnoremap <silent> <expr> <C-E> context#util#map('<C-E>')
    nnoremap <silent> <expr> zz    context#util#map('zz')
    nnoremap <silent> <expr> zb    context#util#map('zb')
endif

nnoremap <silent> <expr> zt context#util#map_zt()
nnoremap <silent> <expr> H  context#util#map_H()

Note how we have extra mappings for when the WinScrolled autocommand doesn't exist.

Contribute

Please feel free to open an issue or pull request if there's anything which you'd like to see improved or added to this plugin.

If you made a change to the regex settings and feel like it might be generally useful, please let me know so I can consider updating the defaults.

Thank you! 😘

context.vim's People

Contributors

breuerfelix avatar jerryliu55 avatar maxigit avatar midchildan avatar nkakouros avatar pratikbhusal avatar weirdsmiley avatar wellle avatar yut23 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

context.vim's Issues

Add option to disable ellipis

The ellipis adds too much noise for my taste - an option would be great!
Especially with arrays of objects in JSON-Files it may result in { ··· }, { ··· }, { ··· }, { ··· }, {

Thank you!

Conflict with `vim-which-key`

Hi,
Context.vim is a great tool for me. Thanks your efforts to build such a great plugin.

However, I found it conflicts with vim-which-key.

Here are the steps to reproduce the conflictions.

  1. Run your cursor to the line to trigger context.vim
    image

  2. Enter your registered key to trigger vim-which-key popup window
    image
    Then you can see that the top of the window become strange

  3. Esc to exit vim-which-key
    image
    Then it seems that the cursor will jump to the top split window created by context.vim.

It's very strange.

Thanks in advance if you can help to fix the issue.

Vim code is inserted when using `<c-o>zz` in insert mode

Steps to reproduce:

  1. Open a buffer
  2. Enter insert mode
  3. Type: <C-o>zz

What happens:

zz is executed, but you see the text :call context#update('zz') inserted.

What should happen:
zz should be executed and no text inserted.

Tested on latest neovim.

Tab characters don't respect `tabstop`

We indent by tabs at work. For readability, i set tabstop=4, but now this

int some_function() {
<tab>if (something) {
<tab><tab>// blah
<tab><tab>// blah
<tab><tab>// blah
<tab><tab>some_line();
<tab><tab>// blah

is rendered like this

int some_function() {
        if (something) {
==================================== <context.vim>
        some_line();
        // blah

because context.vim renders tabs as 8 spaces, but vim (correctly) as 4 spaces.

Disable default 'H' mapping

The default mapping in this plugin
nnoremap <silent> <expr> H context#util#map_H()
is interfering with my existing mapping of the H key.

How do I disable the mapping from this plugin in my .vimrc?

I tried adding my mapping of nnoremap H :bp<CR> after the plugin section in my .vimrc, but that still isn't overwriting the plugin mapping.

Can an option be added to disable or change the default mappings?

Artifacts to the left of the context window

First of all, great job on this plugin, love the idea!

I'm seeing some artifacts to the left hand side of the context window.

Screen Shot 2020-01-27 at 8 38 14 AM

Any idea what could be causing this?

P.S. That screenshot is from the 10-cursor-line-filtered branch, but I'm seeing the same artifacts on master as well.)

High CPU usage when scroll

Very cool idea. But there are some performance problems. When I continuous scrolling, the nvim process take up high CPU usage.
image

Overlap in visual mode

If you jump into visual mode, and and move upwards, you will end up behind the context window.

E.g. see here (red is the current cursor).
2020-05-01-132749_558x240_scrot

So if you want to see what you are visualizing, you need to manually move the screen with C-y, which is annoying. Any chance of fixing that?

Context of cursor line, not of topmost line

I just installed the plugin and I find it very nice.

I was wondering, however. Take this screen:

      def item_exists(                                                                                                                    ) -> ItemExists:                                                                                                              
          if exists:                                                                                                                
              archive_query = {                                                                                                     
                  "query": {                                                                                                        
                      "bool": {                                                                                                     
                          "must": [                                                                                                 
                          ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ <context.vim> 
+ 202                     ]                                                                                                         
+ 203                 }                                                                                                             
+ 204             },                                                                                                                
+ 205             "size": 2,                                                                                                        
+ 206             "_source": False,                                                                                                 
+ 207             "sort": [{"id": {"order": "desc"}}],                                                                              
+ 208         }                                                                                                                     
+ 209         hits = es.search(                                                                                                     
+ 210             index=archive_index, doc_type=DOCUMENT_DOC_TYPE, body=archive_query,                                              
+ 211         )["hits"]["hits"]                                                                                                     

The topmost line shown in the buffer is in the middle of a messy ES query (are there any other kind? :) ), so the context is quite deep.
And if I were editing the query, that would be perfect.

However, if my cursor is, say, at line 210, I don't really care about all that: I would like the context of that line. In this case:

      def item_exists(                                                                                                                    ) -> ItemExists:                                                                                                              
          if exists:   

Is this possible?

Peek context hierarchy

Navigating long structured hierarchies can be tiresome especially in indentation-based code like YAML and Python. However, the context floating window and plugin mechanics can often feel like an over-kill, while all I want is taking a peek on the topmost hierarchy levels, so I can take a quick mental-note.
It would be awesome having a shortcut for opening context.vim floating window only once, as a sheer pop-up overview, and disappear after cursor movement, without any other side-effects. As all the mechanics exist already for rendering the popup's content, I hope you see this suggestion as valuable as I 😃

Make async, or faster?

Very cool idea! Unfortunately it's far too slow for me to use; it prevents me from navigating around. Perhaps you could allow shelling out to a very fast grepper like rg, or somehow run everything asynchronously in the background so it doesn't slow down the editor?

Cheers!

context.vim works slowly when writing vue file

Hi, I am a frontend developer using context.vim to write some vue projects. I think this context idea is really awesome, however, the performance is too bad. I can clearly see flashing on the screen, and I can barely write any code when moving up and down.

Now I decide to get away from context.vim due to the performance problem, If you could solve it, I would definitely be back.

Using treesitter on neovim?

Thanks author for context.vim first, i think it's really cool!
I also use treesitter on neovim by https://github.com/nvim-treesitter/nvim-treesitter. And I think it may be suitable to implement the feature of context.vim.
Since treesitter already parse code to AST, we should get the context naturally. And this may more efficient than regular expressions.
Further more, This way should remain the highlight of the header line of context i think, instead of using a separate highlight.
I also opened an issue at nvim-treesitter/nvim-treesitter#358.

Question: context window color

Hello,

Thanks for your plugin,
is there a way to change the color of the text in the context window OR to add a clear separator between the context window and the current text ? I would like to have a clear distinction between my code and the context given by this plugin :)

Best,
Charles

Disable in preview window

IMHO there seems to be no reason to have this plugin enabled in the preview window, but there is currently no way to deactivate it there, as far as I can see.

Follow cursor rather than top of the window

Currently, at least in my setup, the context window follows the top of the window, not the cursor. So if you have two short functions, one is at the top and one is in the middle or bottom of the screen, even if you cursor is at the bottom of the screen the context will show the first function at the top of the screen. Is there any way to have it follow the cursor?

Custom indent function

I've been using this plugin for a couple weeks and I'm loving it. However, It will be nice if it could work with headings like markdown or org-mode (#, ##, ### ) (and even better with both indent and heading at the same time). I notice the code use the build-in indent function, will it be possible to allows the user to use is own function ?

Setting g:Context_indent per filetype

Is it possible to set g:Context_indent to a different value for different file types? I have one filetype that I currently blacklist, but would want to specify an indent function for it to make it work.

I can describe this in more detail if necessary.

Some error pops up randomly

sometimes this error shows up and the plugin seems deactivated afterwards, I have to restart vim in order to make it work again

Error detected while processing function context#update[27]..<SNR>108_update_context[131]..<SNR>108_show_in_preview:
line   39:
E441: There is no preview window

floating window, sometimes additionally rendered somewhere else?

First of all, really helpful plugin for bigger codebases / files and smaller screens. I really like it.

But I often have the some old context rendered into the middle of the window. See screenshot.

image

It's somehow related to my FZF window, because it's in exactly the same position (I use a custom method to put fzf into a floating window.

I'm definitely not good enough in vim/neovim to say it the problem is something with context here, or with my method.

Ruby "filetype" unknown

Here's an example where I open a Ruby script and jump to the bottom of the file. I see a "filetype unknown" error
image

When I run :set ft I see:
image

(My statusline also prints the filetype in the bottom right corner, and it also clearly says "ruby")

Empty lines displayed in some files.

Steps to reproduce:

  • Open vim with not too high window (50 visible lines is OK)
  • Open attached sample file
  • Press ctrl+e 10 times
  • Observe that context only displays 1 blank line (screenshot)
    image

Sample file:

import React from 'react'
import screenfull from 'screenfull'

import { shallow } from 'enzyme'

import {
  BrowserDetector,
  ListDimensionsUpdater,
  WebRTCWrapper,
  isInConferenceUsingPhone,
  publishVideoStreamMessage,
} from '../../../app/services'
import {
  ChatCallsChannelHandler,
  WebRTCHelpers,
  WebRTCDevices,
  changedCalls,
} from '../../../app/Conference/services'



































































compatibility with Vim versions earlier than 8.0.1630

Since 8.0.1630 vim has a built-in trim(var) function to strip leading and trailing whitespace from var. If support for earlier Vim versions is planned, then substitute(var,'^\s*\|\s*$','') will achieve the same.

Option to disable border and tag

Thanks for this plugin, it seems very useful!

I would be happy if I could disable the border and tag line. Since I use a slightly different background on the context buffer, I don't really need that line.

On a similar note, I also think it should be possible to remove/disable the tag in the border.

Make it work with folds and wrapped lines

Hi, thanks for this awesome plugin. It's improved my workflow a lot.

Are the signed contexts below expected?

image

In the line where my cursor is on, they're just cluttering my reading on.

Undefined variable: v:vim_did_enter on old versions of vim

Context doesn't do any kind of version check in plugin/context.vim.

Not sure what other features you use, but maybe add a check to the top:

if v:version < 800 | finish | endif

On vim 7.4.52 (ubuntu) I see:

  • Undefined variable: v:vim_did_enter
  • Unknown function: win_getid

(I have some machines with old vim but the same config.)

Can't close last window in tab

When I hit ZQ or :q I get error:
E5601: Cannot close window, only floating window would remain
Expected is to normally close the window.

Never allow the cursor to be behind the popup (forcing it to the bottom)

nvim info:

NVIM v0.5.0-dev
Build type: RelWithDebInfo
Lua 5.1
Compilation: /usr/bin/cc -g -O2 -fdebug-prefix-map=/build/neovim-LDECaw/neovim-0.5.0+ubuntu1+git202001312020-14a8b3b-00e710e=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/build/neovim-LDECaw/neovim-0.5.0+ubuntu1+git202001312020-14a8b3b-00e710e/build/config -I/build/neovim-LDECaw/neovim-0.5.0+ubuntu1+git202001312020-14a8b3b-00e710e/src -I/build/neovim-LDECaw/neovim-0.5.0+ubuntu1+git202001312020-14a8b3b-00e710e/.deps/usr/include -I/usr/include -I/build/neovim-LDECaw/neovim-0.5.0+ubuntu1+git202001312020-14a8b3b-00e710e/build/src/nvim/auto -I/build/neovim-LDECaw/neovim-0.5.0+ubuntu1+git202001312020-14a8b3b-00e710e/build/include
Compiled by buildd@lcy01-amd64-015

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Plugin config:

let g:context_highlight_border = 'LineNr'
let g:context_border_char = '⬍'

Presentation: https://webmshare.com/play/YzDKO

Resizing a split does not resize the context window

I am using Neovim:

NVIM v0.5.0-357-g405f49a9b
Build type: RelWithDebInfo
LuaJIT 2.0.5
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/neovim-git/build/config -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/neovim-git/src -I/usr/include -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/neovim-git/build/src/nvim/auto -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/neovim-git/build/include

I have installed context.vim using vim-plug. These are the only two plugins running and (as far as I could tell) there was no other config going on, but the installation of the two plugins and context.vim's config:

  let g:context_border_char = '━'
  let g:context_filetype_blacklist = ['nerdtree', 'help']

I have two vertical splits:
Screenshot_20200206_223309

Pressing in normal mode 10<C-w> < (10 ctrl-w <), results in:

Screenshot_20200206_223320

The context.vim window does not get resized.

Activate on per-window basis

What a wonderful plugin. It certainly shines for me when working on long YAML files where it's easy to lose the context and hierarchy of structures. Long messy Python files also gain better perspective with this plugin. Nevertheless, plugin's behavior is obtrusive, not by its own fault, but performance gets a hit and the essence of "always enabled" on all windows can become a nuisance. Therefore, I wish there was a way to make context.vim toggle on a per-window basis, only when I need its help.

My workaround is mapping a toggle shortcut with this function and manage autocmds and mappings myself:

let g:context_enabled = 0
let g:context_add_mappings = 0
let g:context_add_autocmds = 0

command! ContextToggleCustom call s:context_toggle()
map <silent> <Plug>(context-toggle) <Cmd>ContextToggleCustom<CR>

function! s:context_toggle()
	if ! exists('g:context') || g:context.enabled == 0
		augroup context.vim
			autocmd!
			autocmd BufAdd       * call context#update('BufAdd')
			autocmd BufEnter     * call context#update('BufEnter')
			autocmd CursorMoved  * call context#update('CursorMoved')
			autocmd VimResized   * call context#update('VimResized')
			autocmd CursorHold   * call context#update('CursorHold')
			autocmd User GitGutter call context#update('GitGutter')
		augroup END
		nnoremap <silent>        <C-Y> <C-Y>:call context#update('C-Y')<CR>
		nnoremap <silent>        zz     zzzz:call context#update('zz')<CR>
		nnoremap <silent>        zb     zbzb:call context#update('zb')<CR>
		nnoremap <silent> <expr> <C-E>            context#mapping#ce()
		nnoremap <silent> <expr> zt               context#mapping#zt()
		nnoremap <silent> <expr> k                context#mapping#k()
		nnoremap <silent> <expr> H                context#mapping#h()
		ContextEnable
		ContextActivate
	else
		ContextDisable
		nunmap <C-y>
		nunmap zz
		nunmap zb
		nunmap <C-e>
		nunmap zt
		nunmap H
		" Revert mapping back to accelerated-jk, if installed.
		if dein#tap('accelerated-jk')
			nmap <silent>k <Plug>(accelerated_jk_gk)
		else
			nunmap k
		endif
		autocmd! context.vim BufAdd *
		autocmd! context.vim BufEnter *
		autocmd! context.vim CursorMoved *
		autocmd! context.vim VimResized *
		autocmd! context.vim CursorHold *
	endif
endfunction

Thank you for this wonderful plugin :)

line number and jumping to context line

It would be nice to be able to jump to a line you can see the context window (like when you press H).
I personnaly will be happy for it to be mapped to <count>H but any mapping will do.
Alternatively, displaying the line number in the context window (in accordance with set number and set relativenumber would help.

Cannot open file on first line

When trying to open a file on the first line with context.vim enabled (either by vim <Filename> or vim +1 <Filename>) the file will actually be opened on the second line. For all other line numbers there is no problem (i.e. vim +42 <Filename> will open the file on line 42 and not 43).

I hope this is not too petty an issue, but it is kind of annoying when you use vim as an editor for git commit messages.

Flickering behavior due to redrawing

This is a fantastic plugin -- great idea, I like it pretty much.

One small thing that annoys me is that, whenever I scroll (e.g. press j many times) the buffer, all the buffer contents seem to be redrawn and because of this the vim screen flickers. Any solution to this?

I am using neovim 0.4.3 (linux), TERM=xterm-256color with termguicolors enabled.

Problem with `scrolloff`

Hi, I've set scrolloff=0 in my vim config. Every time I open context and close it, the scrolloff option is not taken into account anymore, though scrolloff is still 0. It seems the popup stays there even when it is not.

Thank you for the plugin.

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.