Giter VIP home page Giter VIP logo

vim-chalk's Introduction

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. ๐ŸŽ‰

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:

    set foldmethod=marker
    
    let g:chalk_char = "."       " The character used as padding
                                 " 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
    
    
    " Create fold at visual selection
    vmap zf <Plug>Chalk
    " Create fold at operator movement
    nmap zf <Plug>Chalk
    " Create fold for specified number of lines
    nmap zF <Plug>ChalkRange
    
    " Create single (opening) fold marker at current level or specified count
    nmap Zf <Plug>SingleChalk
    " Create single (opening) fold marker at next levelor specified count
    nmap ZF <Plug>SingleChalkUp
    
    
    " Increment current fold level
    nmap =z <Plug>ChalkUp
    " Decrement current fold level
    nmap -z <Plug>ChalkDown
    " Increment levels in selection
    vmap =z <Plug>ChalkUp
    " Decrement levels in selection
    vmap -z <Plug>ChalkDown

    (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:

vim-chalk's People

Contributors

dbmrq avatar domgetter avatar hupfdule 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

Watchers

 avatar  avatar  avatar

vim-chalk's Issues

Can it support foldclose mark?

" dbmrq/vim-chalk {{{3 "
" cursor in there
" 3}}} dbmrq/vim-chalk "

when i press <plug>Chalkup, 1st 3 will be 4. but 2nd will not.

thanks!

(Help) Keybind Question

First, thank you! I love this plugin!

Question:

Most of the time, when I want to create a fold, I use 3zF,
It creates an opening, a blank line for insert, and a closing:

" test ........ {{{1

" ............. {{{1

How would I create a mapping for this, for example with <Leader>f ?

Thank you again! great improvement on origami!

if set textwidth=80, it will not align right

if set textwidth=80, it will not align right. So I must set textwidth=0 before
use this plugin. Can it be solved by a better method?

function! init#ChalkUp_v() "{{{
	let l:textwidth = &textwidth
	setlocal textwidth =0
	'<, '>call chalk#makeFold('')
	let &textwidth = l:textwidth
endfunction "}}}
vnoremap zf :<C-U>call init#ChalkUp_v()<CR>

" error

let g:foo='"'

if <plug>chalk it will think " is a comment, in fact, it is a string.

thanks!

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.