autocommands - chimay/wheel GitHub Wiki

Auto group

It's a good idea to group all your wheel autocommands, e.g. :

augroup wheel
	autocmd ...
	autocmd ...
	...
augroup END

Be aware that the autogroup wheel-mandala is used for dedicated buffers local autocommands, so you can't use this name.

Auto read

To enable autoread, you need to add an autocommand on vim enter :

autocmd VimEnter * call wheel#void#init()

Auto write

To enable autowrite, you need to add an autocommand on vim leave :

autocmd VimLeave * call wheel#void#exit()

Auto update

By default, locations are only updated manually, with <M-w><M-$>. This way, you can update the wheel only when you want to do so.

Nevertheless, if you want to update your cursor position each time you leave a buffer, you can also use the classic BufLeave event :

autocmd BufLeave * call wheel#vortex#update()

Before jump

It is possible to update automatically your locations before each jump to a new wheel location. Just add the update function to the WheelBeforeJump user event :

autocmd User WheelBeforeJump call wheel#vortex#update()

This autocmd is run before any jump, as soon as you use a wheel navigation function :

  • next/previous element
  • switch to element
  • switch in index, history, frecency
  • ...

Before organize

To update automatically your locations before each operation involving a wheel element, just add the update function to the WheelBeforeOrganize user event :

autocmd User WheelBeforeOrganize call wheel#vortex#update()

This autocmd is run before each organizing function :

  • add
  • rename
  • remove
  • reorder
  • reorganize
  • ...

Before write

To update automatically your locations before writing the wheel to a file, just add the update function to the WheelBeforeWrite user event :

autocmd User WheelBeforeWrite call wheel#vortex#update()

After jump

The WheelAfterJump user event happens after any jump to a wheel location, as soon as you use a wheel navigation function.

You can use it to add a post-jump operation.

This example folds everything except the cursor line :

autocmd User WheelAfterJump norm zMzx

This example opens recursively the folds under the cursor line :

autocmd User WheelAfterJump norm zCzO

Auto follow

If you wish the wheel location to auto-follow the current buffer each time you enter a window, you can add this autocommand :

autocmd WinEnter * call wheel#projection#follow()

This means that each time you enter a tab or a window by using a native command (like gt, :tabnext, CTRL-W_CTRL-W and so on), the plugin will check if the current file name is in the wheel. If true, it will adjust its state to match the file.

Launch it manually

You can launch the follow routine manually with <M-w><M-$> by default.

Edit & add

If you want to edit a file and add it to the current group (circle), you can use <plug>(wheel-add-file). It is bound to <M-w>+f by default.

To edit and add a buffer, you can use <plug>(wheel-add-buffer), bound to <M-w>+b by default.

Other events

I find these events less useful but they are worth mentioning, just in case you need them in your workflow.

If you want to trigger the auto-follow process when you edit a file with a native vim command (like :edit), just add it to the BufRead event :

autocmd BufRead * call wheel#projection#follow()

Same thing when you enter a buffer with a native vim command (like :buffer), just add it to the BufEnter event :

autocmd BufEnter * call wheel#projection#follow()

After native

The WheelAfterNative user event happens after any jump using a native (neo)vim function.

You can use it to auto-follow after a native operation :

autocmd User WheelAfterNative call wheel#projection#follow()

MRU files

If you want to record a list of the files you edited without adding them to the wheel :

autocmd BufRead * call wheel#attic#record()

Yank ring

If you want to record your yanks/delete, you can add this autommand to your init file :

autocmd TextYankPost * call wheel#codex#add()

Example

Here is an example of a complete autocommands configuration :

augroup wheel
	" Clear the group
	autocmd!
	" On vim enter, for autoreading
	autocmd VimEnter * call wheel#void#init()
	" On vim leave, for autowriting
	autocmd VimLeave * call wheel#void#exit()
	" Update location line & col before leaving a window
	autocmd BufLeave * call wheel#vortex#update()
	" Executed before jumping to a location
	autocmd User WheelBeforeJump call wheel#vortex#update()
	" Executed before organizing the wheel
	autocmd User WheelBeforeOrganize call wheel#vortex#update()
	" Executed before writing the wheel
	autocmd User WheelBeforeWrite call wheel#vortex#update()
	" Executed after jumping to a location
	"autocmd User WheelAfterJump norm zMzx
	" For current wheel location to auto follow window changes
	autocmd WinEnter * call wheel#projection#follow()
	" For current wheel location to follow on editing, buffer loading
	"autocmd BufRead * call wheel#projection#follow()
	" For current wheel location to follow on entering buffer
	"autocmd BufEnter * call wheel#projection#follow()
	" Executed after a native jump
	"autocmd User WheelAfterNative call wheel#projection#follow()
	" Add current non-wheel file to MRU files
	autocmd BufRead * call wheel#attic#record()
	" To record your yanks in the yank ring
	autocmd TextYankPost * call wheel#codex#add()
augroup END
⚠️ **GitHub.com Fallback** ⚠️