项目作者: dbmrq

项目描述 :
:pencil2: Better fold markers
高级语言: Vim script
项目地址: git://github.com/dbmrq/vim-chalk.git
创建时间: 2016-09-29T05:55:07Z
项目社区:https://github.com/dbmrq/vim-chalk

开源协议:

下载


chalk.vim

Vim can get confused when handling multiple nested fold markers.

The answer is to include a level (like this: "{{{1), but I’m too lazy for that. Enter Chalk. It automatically adds the level to folds you create with zf and increments all nested folds for you. There are also specific mappings and commands to increment and decrement markers while keeping them balanced and more. :tada:

chalk

Update: Inspired by kshenoy/vim-origami, I updated Chalk with the option to keep the markers aligned. My version aligns both the opening and closing markers and it also allows you to choose a “filler” character for the padding. On the other hand, it doesn’t support “staggered” alignment and the markers are always aligned to the textwidth setting.

chalk2

Quick start

  1. Install Chalk using your favorite plugin manager or copy each file to its corresponding directory under ~/.vim/.

  2. Add this to your .vimrc:

    ```vim
    set foldmethod=marker

    let g:chalk_char = “.” “ The character used as padding

    1. " when aligning markers

    “ Files for which to add a space between the marker and the current text
    au BufRead,BufNewFile *.vim let b:chalk_space_before = 1

  1. " Create fold at visual selection
  2. vmap zf <Plug>Chalk
  3. " Create fold at operator movement
  4. nmap zf <Plug>Chalk
  5. " Create fold for specified number of lines
  6. nmap zF <Plug>ChalkRange
  7. " Create single (opening) fold marker at current level or specified count
  8. nmap Zf <Plug>SingleChalk
  9. " Create single (opening) fold marker at next levelor specified count
  10. nmap ZF <Plug>SingleChalkUp
  11. " Increment current fold level
  12. nmap =z <Plug>ChalkUp
  13. " Decrement current fold level
  14. nmap -z <Plug>ChalkDown
  15. " Increment levels in selection
  16. vmap =z <Plug>ChalkUp
  17. " Decrement levels in selection
  18. vmap -z <Plug>ChalkDown
  19. ```
  20. (Choose the mappings you prefer. These are only suggestions.)

Commands

:ChalkUp and :ChalkDown

Increment or decrement the fold marker levels for the specified range (or the whole file, if no range is given).

:ChalkAlign

Align all markers in the current document.

Mappings

<Plug>Chalk

This works just like Vim’s zf, creating a new fold at the current selection (in visual mode) or motion (in normal mode). The difference is that it also adds the fold level automatically according to where you’re at.

<Plug>ChalkRange

This works just like Vim’s zF, creating a fold for the specified number of lines, but with the same perks as above.

<Plug>SingleChalk

The previous mappings add both the opening and closing fold markers. This one, on the other hand, adds a single opening marker at current line. If a count is specified before the mapping, that count is used as the level number. If no count is specified, this mapping will use the current level.

<Plug>SingleChalkUp

This mapping works like the previous one, but if no count is specified, it will use a level deeper than the current fold’s.

<Plug>ChalkUp and <Plug>ChalkDown

When used in Normal mode, these mappings will increment or decrement the pair of markers (or the single marker, if you’re into that sort of thing) at the current level.

When used in Visual mode, they’ll increment or decrement every marker in the visual selection. Not that unlike their Normal mode counterparts the Visual mode mappings won’t keep the opening and closing markers balanced unless they’re both inside the selection.

Options

g:chalk_align

By default, Chalk will align your fold markers to the right according to your textwidth setting. If you want to disable that behavior, set g:chalk_align to 0.

g:chalk_char

The character used to align markers to the right. The default is a space (" ").

g:chalk_edit

By default, Chalk will leave you in insert/replace mode after creating a new fold. You can disable this behavior by setting g:chalk_edit to 0.

b:chalk_space_before

By default, Chalk won’t add a space between an existing line’s text and the fold marker. This is good for a language like TeX, in which spaces make a difference, but may be undesirable for other languages, so you can change this behavior by setting b:chalk_space_before to 1 for specific file types. E.g.: au BufRead,BufNewFile *.vim let b:chalk_space_before = 1.

See also

You may also be interested in my other plugins: