Fixed vim and zsh
This commit is contained in:
1
vim/plugins/FastFold/.gitignore
vendored
Normal file
1
vim/plugins/FastFold/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
doc/tags
|
106
vim/plugins/FastFold/README.md
Normal file
106
vim/plugins/FastFold/README.md
Normal file
@ -0,0 +1,106 @@
|
||||
# What good will FastFold do?
|
||||
|
||||
Automatic folds (that is, folds generated by a fold method different
|
||||
from `manual`), bog down VIM noticeably in insert mode. They are also often
|
||||
recomputed too early (for example, when inserting an opening fold marker
|
||||
whose closing counterpart is yet missing to complete the fold.)
|
||||
|
||||
See http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text
|
||||
for a discussion.
|
||||
|
||||
With this plug-in, the folds in the currently edited buffer are updated by an
|
||||
automatic fold method only
|
||||
|
||||
- when saving the buffer
|
||||
- when closing or opening folds (zo, za, zc, etc...)
|
||||
- when moving or operating fold-wise (zj,zk,[z,]z)
|
||||
- when typing `zuz` in normal mode
|
||||
|
||||
and are kept as is otherwise (by keeping the fold method set to `manual`).
|
||||
|
||||
# Example Setup
|
||||
|
||||
Each of these triggers for updating folds can be modified or disabled by adding
|
||||
the lines
|
||||
|
||||
```vim
|
||||
nmap zuz <Plug>(FastFoldUpdate)
|
||||
let g:fastfold_savehook = 1
|
||||
let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C']
|
||||
let g:fastfold_fold_movement_commands = [']z', '[z', 'zj', 'zk']
|
||||
```
|
||||
|
||||
to the file `~/.vimrc` (respectively `%USERPROFILE%/_vimrc` on Microsoft Windows).
|
||||
|
||||
For example, by adding
|
||||
|
||||
```vim
|
||||
let g:tex_fold_enabled=1
|
||||
let g:vimsyn_folding='af'
|
||||
let g:xml_syntax_folding = 1
|
||||
let g:php_folding = 1
|
||||
let g:perl_fold = 1
|
||||
```
|
||||
|
||||
to the `.vimrc` file and installing this plug-in, the folds in a TeX, Vim, XML,
|
||||
PHP or Perl file are updated by the `syntax` fold method when saving the
|
||||
buffer, opening, closing, moving or operating on folds, or typing `zuz` in
|
||||
normal mode and are kept as is otherwise.
|
||||
|
||||
*Set fold methods for every file type only*! Setting it globally risks that FastFold assumes the wrong, global, fold method instead of that intended by the file type plug-in, for example TagList.
|
||||
|
||||
# Configuration
|
||||
|
||||
- If you prefer that folds are only updated manually but not when saving the buffer,
|
||||
then add `let g:fastfold_savehook = 0` to your `.vimrc`.
|
||||
|
||||
- If you prefer that folds are updated whenever you close or open folds by a
|
||||
standard keystroke such as `zx`,`zo` or `zc`, then add `let
|
||||
g:fastfold_fold_command_suffixes = []` to your `.vimrc`.
|
||||
|
||||
The exact list of these standard keystrokes is `zx,zX,za,zA,zo,zO,zc,zC` and
|
||||
it can be customized by changing the global variable
|
||||
`g:fastfold_mapsuffixes`. If you wanted to intercept all possible fold
|
||||
commands (such as zr,zm,...), change this to:
|
||||
|
||||
```vim
|
||||
let g:fastfold_fold_command_suffixes =
|
||||
['x','X','a','A','o','O','c','C','r','R','m','M','i','n','N']
|
||||
```
|
||||
|
||||
- If you prefer that this plug-in does not add a normal mode mapping that updates
|
||||
folds (that defaults to `zuz`), then add
|
||||
`nmap <SID>(DisableFastFoldUpdate) <Plug>(FastFoldUpdate) ` to your `.vimrc`.
|
||||
|
||||
You can remap `zuz` to your favorite keystroke, say `<F5>`, by adding
|
||||
`nmap <F5> <Plug>(FastFoldUpdate)` to your `.Vimrc`.
|
||||
|
||||
There is also a command `FastFoldUpdate` that updates all folds and its
|
||||
variant `FastFoldUpdate!` that updates all folds and echos by which fold
|
||||
method the folds were updated.
|
||||
|
||||
# Addons
|
||||
|
||||
## Vim-Stay
|
||||
|
||||
`FastFold` integrates with the plug-in
|
||||
[vim-stay](https://github.com/kopischke/vim-stay/issues) that restores the
|
||||
folds of a file buffer by `:mkview` and `:loadview`.
|
||||
|
||||
## Custom Fold Text
|
||||
|
||||
A `CustomFoldText()` function that displays the percentage of the number of buffer lines that the folded text takes up and indents folds according to their nesting level, similar to [that](http://www.gregsexton.org/2011/03/improving-the-text-displayed-in-a-fold/) by Greg Sexton, is available at
|
||||
|
||||
http://www.github.com/Konfekt/FoldText
|
||||
|
||||
## Fold Text-Object
|
||||
|
||||
Create a fold text object, mapped to `iz` and `az`, by adding the lines
|
||||
|
||||
```vim
|
||||
xnoremap iz :<c-u>FastFoldUpdate<cr><esc>:<c-u>normal! ]zv[z<cr>
|
||||
xnoremap az :<c-u>FastFoldUpdate<cr><esc>:<c-u>normal! ]zV[z<cr>
|
||||
```
|
||||
|
||||
to the file `~/.vimrc` (respectively `%USERPROFILE%/_vimrc` on Microsoft Windows).
|
||||
|
153
vim/plugins/FastFold/doc/FastFold.txt
Normal file
153
vim/plugins/FastFold/doc/FastFold.txt
Normal file
@ -0,0 +1,153 @@
|
||||
FastFold, folding optimization *FastFold* *fastfold*
|
||||
|
||||
===========================================================================
|
||||
0. Introduction ~
|
||||
*FastFold-intro* *fastfold-intro*
|
||||
|
||||
Automatic folds - that is, folds generated by a fold method different
|
||||
from `manual` - bog down VIM considerably in insert mode. Also, they are often
|
||||
re-evaluated prematurely for example, when inserting an opening fold marker
|
||||
whose closing counterpart has yet to be added to complete the fold.
|
||||
|
||||
See http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text
|
||||
for a discussion.
|
||||
|
||||
With this plug-in, the folds in the currently edited buffer are updated when
|
||||
certain triggers are met:
|
||||
|
||||
- when saving the buffer
|
||||
- when closing or opening folds (zo, za, zc, etc...)
|
||||
- when moving or operating fold-wise (zj,zk,[z,]z)
|
||||
- when typing `zuz` in normal mode
|
||||
|
||||
===========================================================================
|
||||
1. Commands ~
|
||||
*FastFold-commands* *fastfold-commands*
|
||||
*FastFoldUpdate!*
|
||||
|
||||
- `:FastFoldUpdate` updates all folds in the current buffer.
|
||||
- `:FastFoldUpdate!` updates all folds & echoes what fold method was used
|
||||
|
||||
- The mapping `zuz` that invokes `:FastFoldUpdate!` can be changed to your
|
||||
favorite keystroke, say `<F5>`, by adding
|
||||
>
|
||||
nmap <F5> <Plug>(FastFoldUpdate)
|
||||
<
|
||||
to your `.vimrc`. It can be disabled by adding
|
||||
>
|
||||
nmap <SID>(DisableFastFoldUpdate) <Plug>(FastFoldUpdate)
|
||||
<
|
||||
===========================================================================
|
||||
2. Config ~
|
||||
*FastFold-config* *fastfold-config*
|
||||
|
||||
Each of the above triggers can be enabled or disabled by setting the
|
||||
matching global flags in your `.vimrc`. Default values are shown.
|
||||
>
|
||||
let g:fastfold_savehook = 1
|
||||
let g:fastfold_fdmhook = 0
|
||||
nmap zuz <Plug>(FastFoldUpdate)
|
||||
let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C']
|
||||
let g:fastfold_fold_movement_commands = [']z', '[z', 'zj', 'zk']
|
||||
<
|
||||
For example, by adding the following to your `.vimrc`
|
||||
>
|
||||
let g:tex_fold_enabled=1
|
||||
let g:vimsyn_folding='af'
|
||||
let g:xml_syntax_folding = 1
|
||||
let g:php_folding = 1
|
||||
let g:perl_fold = 1
|
||||
<
|
||||
You will enable tex, vim, xml, php and perl syntax folding.
|
||||
|
||||
Set fold methods for every file type only! Setting it globally risks that
|
||||
FastFold assumes the wrong, global, fold method instead of that intended by the
|
||||
file type plug-in, for example TagList.
|
||||
|
||||
-----------------------------
|
||||
|
||||
- FastFold updates all folds when you open or close folds by the commands
|
||||
zx, zX, za, zA, zo, zO, zc, zC. This list of commands is configured by
|
||||
>
|
||||
let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C']
|
||||
<
|
||||
To intercept all possible fold commands (such as zr,zm,...),change this to
|
||||
>
|
||||
let g:fastfold_fold_command_suffixes =
|
||||
['x','X','a','A','o','O','c','C','r','R','m','M','i','n','N']
|
||||
<
|
||||
To disable all interceptions, change this to
|
||||
>
|
||||
let g:fastfold_fold_command_suffixes = []
|
||||
<
|
||||
- FastFold updates all fold when you move or operate fold-wise by
|
||||
the commands zj,zk,[z or ]z. This list of commands is configured by
|
||||
>
|
||||
let g:fastfold_fold_movement_commands = [']z', '[z', 'zj', 'zk']
|
||||
<
|
||||
It can be disabled by
|
||||
>
|
||||
let g:fastfold_fold_movement_commands = []
|
||||
<
|
||||
- FastFold updates all folds when you save a buffer. This hook is set by
|
||||
>
|
||||
let g:fastfold_savehook = 1
|
||||
<
|
||||
- FastFold intercepts every change of the fold method by
|
||||
>
|
||||
let g:fastfold_fdmhook = 1
|
||||
<
|
||||
This is disabled by default as it could interfere with other plugins such as
|
||||
`easymotion`.
|
||||
|
||||
- To disable FastFold for a list of file types, such as 'taglist', add
|
||||
>
|
||||
` let g:fastfold_skip_filetypes`= [ 'taglist' ]
|
||||
<
|
||||
to your 'vimrc'. Default value is [].
|
||||
|
||||
- Add a fold text-object, mapped to `iz` and `az`, by adding the lines
|
||||
|
||||
xnoremap iz :<c-u>FastFoldUpdate<cr><esc>:<c-u>normal! ]zv[z<cr>
|
||||
xnoremap az :<c-u>FastFoldUpdate<cr><esc>:<c-u>normal! ]zV[z<cr>
|
||||
|
||||
to your 'vimrc'.
|
||||
===========================================================================
|
||||
3. Extra Notes ~
|
||||
|
||||
3.1 Related Plugins ~
|
||||
|
||||
`FastFold` integrates with the plug-in `vim-stay` available at
|
||||
|
||||
https://github.com/kopischke/vim-stay
|
||||
|
||||
that stores and restores the last folds by `:mkview` and `:loadview`.
|
||||
|
||||
------------------------------
|
||||
|
||||
A fold-text function `CustomFoldText()` that displays the percentage of the
|
||||
number of buffer lines that the folded text takes up and indents folds
|
||||
according to their nesting level is available at
|
||||
|
||||
http://www.github.com/Konfekt/FoldText
|
||||
|
||||
3.2 Warning ~
|
||||
|
||||
FastFold overwrites your manual folds when saving the currently edited buffer,
|
||||
unless
|
||||
|
||||
- FastFold is disabled for this filetype by `g:fastfold_skip_filetypes`, or
|
||||
- the `foldmethod=manual` since having entered the buffer.
|
||||
|
||||
3.3 API ~
|
||||
|
||||
The last used fold method by which FastFold updates the folds in the current
|
||||
buffer can be read off from the window local variable `w:lastdfm`.
|
||||
|
||||
3.4 Thanks go to... ~
|
||||
|
||||
- starcraftman for providing this documentation, and
|
||||
- blueyed, kopischke, sabauma, willywampa, and many others for reporting
|
||||
issues and suggesting code improvements.
|
||||
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl
|
224
vim/plugins/FastFold/plugin/fastfold.vim
Normal file
224
vim/plugins/FastFold/plugin/fastfold.vim
Normal file
@ -0,0 +1,224 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
" LICENCE PUBLIQUE RIEN À BRANLER
|
||||
" Version 1, Mars 2009
|
||||
"
|
||||
" Copyright (C) 2009 Sam Hocevar
|
||||
" 14 rue de Plaisance, 75014 Paris, France
|
||||
"
|
||||
" La copie et la distribution de copies exactes de cette licence sont
|
||||
" autorisées, et toute modification est permise à condition de changer
|
||||
" le nom de la licence.
|
||||
"
|
||||
" CONDITIONS DE COPIE, DISTRIBUTON ET MODIFICATION
|
||||
" DE LA LICENCE PUBLIQUE RIEN À BRANLER
|
||||
"
|
||||
" 0. Faites ce que vous voulez, j’en ai RIEN À BRANLER.
|
||||
|
||||
if exists('g:loaded_fastfold') || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_fastfold = 1
|
||||
|
||||
let s:keepcpo = &cpo
|
||||
set cpo&vim
|
||||
" ------------------------------------------------------------------------------
|
||||
|
||||
if !exists('g:fastfold_fdmhook') | let g:fastfold_fdmhook = 0 | endif
|
||||
if !exists('g:fastfold_savehook') | let g:fastfold_savehook = 1 | endif
|
||||
if !exists('g:fastfold_fold_command_suffixes')
|
||||
let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C']
|
||||
endif
|
||||
if !exists('g:fastfold_fold_movement_commands')
|
||||
let g:fastfold_fold_movement_commands = [']z', '[z', 'zj', 'zk']
|
||||
endif
|
||||
if !exists('g:fastfold_skip_filetypes') | let g:fastfold_skip_filetypes = [] | endif
|
||||
|
||||
function! s:EnterWin()
|
||||
if exists('w:unchanged')
|
||||
unlet w:unchanged
|
||||
elseif s:Skip()
|
||||
if exists('w:lastfdm')
|
||||
unlet w:lastfdm
|
||||
endif
|
||||
else
|
||||
let w:lastfdm = &l:foldmethod
|
||||
setlocal foldmethod=manual
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:LeaveWin()
|
||||
if exists('w:predifffdm')
|
||||
if empty(&l:foldmethod) || &l:foldmethod is# 'manual'
|
||||
let &l:foldmethod = w:predifffdm
|
||||
unlet w:predifffdm
|
||||
return
|
||||
elseif &l:foldmethod isnot# 'diff'
|
||||
unlet w:predifffdm
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists('w:lastfdm') && &l:foldmethod is# 'diff'
|
||||
let w:predifffdm = w:lastfdm
|
||||
endif
|
||||
|
||||
if exists('w:lastfdm') && &l:foldmethod is# 'manual'
|
||||
if !exists('b:last_changedtick') || b:changedtick > b:last_changedtick
|
||||
let &l:foldmethod = w:lastfdm
|
||||
let b:last_changedtick = b:changedtick
|
||||
else
|
||||
let w:unchanged = 1
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Like windo but restore the current buffer.
|
||||
" See http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers#Restoring_position
|
||||
function! s:WinDo( command )
|
||||
" avoid errors in CmdWin
|
||||
if exists('*getcmdwintype') && !empty(getcmdwintype())
|
||||
return
|
||||
endif
|
||||
" Work around Vim bug.
|
||||
" See https://groups.google.com/forum/#!topic/vim_dev/LLTw8JV6wKg
|
||||
let curaltwin = winnr('#') ? winnr('#') : 1
|
||||
let currwin=winnr()
|
||||
if &scrollopt =~# '\<jump\>'
|
||||
set scrollopt-=jump
|
||||
let l:restore = 'set scrollopt+=jump'
|
||||
endif
|
||||
silent! execute 'keepjumps noautocmd windo ' . a:command
|
||||
silent! execute 'noautocmd ' . curaltwin . 'wincmd w'
|
||||
silent! execute 'noautocmd ' . currwin . 'wincmd w'
|
||||
if exists('l:restore')
|
||||
exe l:restore
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" WinEnter then TabEnter then BufEnter then BufWinEnter
|
||||
function! s:UpdateWin(check)
|
||||
" skip if another session still loading
|
||||
if a:check && exists('g:SessionLoad') | return | endif
|
||||
|
||||
let s:curwin = winnr()
|
||||
call s:WinDo('if winnr() is s:curwin | call s:LeaveWin() | endif')
|
||||
call s:WinDo('if winnr() is s:curwin | call s:EnterWin() | endif')
|
||||
endfunction
|
||||
|
||||
function! s:UpdateBuf(feedback)
|
||||
let s:curbuf = bufnr('%')
|
||||
call s:WinDo("if bufnr('%') is s:curbuf | call s:LeaveWin() | endif")
|
||||
call s:WinDo("if bufnr('%') is s:curbuf | call s:EnterWin() | endif")
|
||||
|
||||
if !a:feedback | return | endif
|
||||
|
||||
if !exists('w:lastfdm')
|
||||
echomsg "'" . &l:foldmethod . "' folds already continuously updated"
|
||||
else
|
||||
echomsg "updated '" . w:lastfdm . "' folds"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:UpdateTab()
|
||||
" skip if another session still loading
|
||||
if exists('g:SessionLoad') | return | endif
|
||||
|
||||
call s:WinDo('call s:LeaveWin()')
|
||||
call s:WinDo('call s:EnterWin()')
|
||||
endfunction
|
||||
|
||||
function! s:Skip()
|
||||
if !s:isReasonable() | return 1 | endif
|
||||
if !&l:modifiable | return 1 | endif
|
||||
if s:inSkipList() | return 1 | endif
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:isReasonable()
|
||||
if &l:foldmethod is# 'syntax' || &l:foldmethod is# 'expr'
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:inSkipList()
|
||||
for ifiles in g:fastfold_skip_filetypes
|
||||
if index(g:fastfold_skip_filetypes, &l:filetype) >= 0
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
command! -bar -bang FastFoldUpdate call s:UpdateBuf(<bang>0)
|
||||
|
||||
nnoremap <silent> <Plug>(FastFoldUpdate) :<c-u>FastFoldUpdate!<CR>
|
||||
|
||||
if !hasmapto('<Plug>(FastFoldUpdate)', 'n') && empty(mapcheck('zuz', 'n'))
|
||||
nmap zuz <Plug>(FastFoldUpdate)
|
||||
endif
|
||||
|
||||
for suffix in g:fastfold_fold_command_suffixes
|
||||
execute 'nnoremap <silent> z'.suffix.' :<c-u>call <SID>UpdateWin(0)<CR>z'.suffix
|
||||
endfor
|
||||
|
||||
for cmd in g:fastfold_fold_movement_commands
|
||||
exe "nnoremap <silent><expr> " . cmd. " ':<c-u>call <SID>UpdateWin(0)<CR>'.v:count." . "'".cmd."'"
|
||||
exe "xnoremap <silent><expr> " . cmd. " ':<c-u>call <SID>UpdateWin(0)<CR>gv'.v:count." . "'".cmd."'"
|
||||
exe "onoremap <silent><expr> " . cmd. " '<esc>:<c-u>call <SID>UpdateWin(0)<CR>' . '\"' . v:register . v:operator . v:count1 . " . "'".cmd."'"
|
||||
endfor
|
||||
|
||||
augroup FastFold
|
||||
autocmd!
|
||||
autocmd VimEnter * call s:init()
|
||||
autocmd BufEnter,WinEnter *
|
||||
\ if !exists('b:last_changedtick') | let b:last_changedtick = b:changedtick | endif
|
||||
augroup end
|
||||
|
||||
function! s:init()
|
||||
call s:UpdateTab()
|
||||
augroup FastFoldEnter
|
||||
autocmd!
|
||||
" Make &l:foldmethod local to Buffer and NOT Window.
|
||||
autocmd BufEnter,WinEnter *
|
||||
\ if exists('b:lastfdm') | let w:lastfdm = b:lastfdm | call s:LeaveWin() | call s:EnterWin() | endif
|
||||
autocmd BufLeave,WinLeave *
|
||||
\ call s:LeaveWin() | call s:EnterWin() |
|
||||
\ if exists('w:lastfdm') | let b:lastfdm = w:lastfdm |
|
||||
\ elseif exists('b:lastfdm') | unlet b:lastfdm | endif
|
||||
|
||||
autocmd BufEnter,WinEnter *
|
||||
\ if &l:foldmethod isnot# 'diff' && exists('b:predifffdm') | call s:UpdateBuf(0) | endif
|
||||
autocmd BufLeave,WinLeave *
|
||||
\ if exists('w:predifffdm') | let b:predifffdm = w:predifffdm |
|
||||
\ elseif exists('b:predifffdm') | unlet b:predifffdm | endif
|
||||
|
||||
" UpdateBuf/Win(1) = skip if another session is still loading.
|
||||
autocmd TabEnter * call s:UpdateTab()
|
||||
|
||||
" BufWinEnter = to change &l:foldmethod by modelines.
|
||||
autocmd BufWinEnter,FileType * call s:UpdateWin(1)
|
||||
" So that FastFold functions correctly after :loadview.
|
||||
autocmd SessionLoadPost * call s:UpdateWin(0)
|
||||
|
||||
" Update folds on reload.
|
||||
autocmd BufReadPost *
|
||||
\ if !exists('b:already_loaded') | let b:already_loaded = 1 |
|
||||
\ else | call s:UpdateBuf(0) | endif
|
||||
" Update folds on saving.
|
||||
if g:fastfold_savehook
|
||||
autocmd BufWritePost * call s:UpdateBuf(0)
|
||||
endif
|
||||
if g:fastfold_fdmhook
|
||||
if exists('##OptionSet')
|
||||
autocmd OptionSet foldmethod call s:UpdateBuf(0)
|
||||
endif
|
||||
endif
|
||||
augroup end
|
||||
endfunction
|
||||
|
||||
" ------------------------------------------------------------------------------
|
||||
let &cpo= s:keepcpo
|
||||
unlet s:keepcpo
|
Reference in New Issue
Block a user