Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tpope committed Dec 24, 2013
0 parents commit 1b577bc
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.markdown
@@ -0,0 +1 @@
See the [contribution guidelines for pathogen.vim](https://github.com/tpope/vim-pathogen/blob/master/CONTRIBUTING.markdown).
63 changes: 63 additions & 0 deletions README.markdown
@@ -0,0 +1,63 @@
# vim-sexp mappings for regular people

I'm really liking my first impressions of [vim-sexp][]. It's like paredit
minus a couple of parts of paredit that are impossibly tricky to implement in
Vim. I'm not too keen on some of the default mappings, though, and in
particular the mappings using the meta key are just an absolute deal breaker
for me and everyone else that uses Vim in a terminal. So I made and published
my own, in an attempt to define a more accessible standard.

[vim-sexp]: https://github.com/guns/vim-sexp

## Installation

You know the drill. Here's a copy and paste to install the works with
[pathogen.vim](https://github.com/tpope/vim-pathogen).

cd ~/.vim/bundle
git clone git://github.com/tpope/vim-sexp-mappings-for-regular-people.git
git clone git://github.com/guns/vim-sexp.git
git clone git://github.com/tpope/vim-repeat.git
git clone git://github.com/tpope/vim-surround.git

## Provided mappings

These mappings supplement rather than replace the existing mappings (despite
vim-sexp's best efforts to thwart this), so if you have muscle memory, fear
not.

### Motion mappings

Vim-sexp uses meta mappings to move element-wise. I've taken over the WORD
motions--`W`, `B`, `E`, `gE`--instead, operating under the theory that those
aren't nearly as useful in a language where so many punctuation marks are
identifier characters. This might be a terrible idea.

### List manipulation mappings

More meta madness in the defaults here. I've taken `>f` and `<f` to move a
form and `>e` and `<e` to move an element.

Slurpage and barfage are handled by `>)`, `<)`, `<(`, and `<)`, where the
angle bracket indicates the direction, and the parenthesis indicates which end
to operate on.

### Insertion mappings

Use `<I` and `>I` to insert at the beginning and ending of a form.

### Mappings inspired by surround.vim

Note that surround.vim out of the box works great with the sexp.vim motions
and text objects. Use `ysaf)`, for example, to surround the current form with
parentheses. To this, we add a few more mappings:

* `dsf`: splice (delete surroundings of form)
* `cse(`/`cse)`/`cseb`: surround element in parentheses
* `cse[`/`cse]`: surround element in brackets
* `cse{`/`cse}`: surround element in braces

## License

Copyright © Tim Pope. Distributed under the same terms as Vim itself.
See `:help license`.
55 changes: 55 additions & 0 deletions after/plugin/sexp.vim
@@ -0,0 +1,55 @@
" after/plugin/sexp.vim - Sexp mappings for regular people
" Maintainer: Tim Pope <code@tpope.net>

if !exists('g:sexp_loaded') || exists("g:after_loaded_sexp")
finish
endif
let g:after_sexp_loaded = 1

augroup sexp
autocmd!
execute 'autocmd FileType' get(g:, 'sexp_filetypes', 'lisp,scheme,clojure') 'call s:sexp_mappings()'
augroup END

function! s:map_sexp_wrap(type, target, left, right, pos)
execute (a:type ==# 'v' ? 'x' : 'n').'noremap'
\ '<buffer><silent>' a:target ':<C-U>let b:sexp_count = v:count<Bar>exe "normal! m`"<Bar>'
\ . 'call sexp#wrap("'.a:type.'", "'.a:left.'", "'.a:right.'", '.a:pos.', 0)'
\ . '<Bar>silent! call repeat#set("'.a:target.'", v:count)<CR>'
endfunction

function! s:sexp_mappings() abort
call s:map_sexp_wrap('e', 'cseb', '(', ')', 0)
call s:map_sexp_wrap('e', 'cse(', '(', ')', 0)
call s:map_sexp_wrap('e', 'cse)', '(', ')', 1)
call s:map_sexp_wrap('e', 'cse[', '[', ']', 0)
call s:map_sexp_wrap('e', 'cse]', '[', ']', 1)
call s:map_sexp_wrap('e', 'cse{', '{', '}', 0)
call s:map_sexp_wrap('e', 'cse}', '{', '}', 1)

nmap <buffer> dsf <Plug>(sexp_splice_list)
nmap <buffer> B <Plug>(sexp_move_to_prev_element_head)
nmap <buffer> W <Plug>(sexp_move_to_next_element_head)
nmap <buffer> gE <Plug>(sexp_move_to_prev_element_tail)
nmap <buffer> E <Plug>(sexp_move_to_next_element_tail)
xmap <buffer> B <Plug>(sexp_move_to_prev_element_head)
xmap <buffer> W <Plug>(sexp_move_to_next_element_head)
xmap <buffer> gE <Plug>(sexp_move_to_prev_element_tail)
xmap <buffer> E <Plug>(sexp_move_to_next_element_tail)
omap <buffer> B <Plug>(sexp_move_to_prev_element_head)
omap <buffer> W <Plug>(sexp_move_to_next_element_head)
omap <buffer> gE <Plug>(sexp_move_to_prev_element_tail)
omap <buffer> E <Plug>(sexp_move_to_next_element_tail)
nmap <buffer> <I <Plug>(sexp_insert_at_list_head)
nmap <buffer> >I <Plug>(sexp_insert_at_list_tail)
nmap <buffer> <f <Plug>(sexp_swap_list_backward)
nmap <buffer> >f <Plug>(sexp_swap_list_forward)
nmap <buffer> <e <Plug>(sexp_swap_element_backward)
nmap <buffer> >e <Plug>(sexp_swap_element_forward)
nmap <buffer> >( <Plug>(sexp_emit_head_element)
nmap <buffer> <) <Plug>(sexp_emit_tail_element)
nmap <buffer> <( <Plug>(sexp_capture_prev_element)
nmap <buffer> >) <Plug>(sexp_capture_next_element)
endfunction

0 comments on commit 1b577bc

Please sign in to comment.