• Stars
    star
    250
  • Rank 161,890 (Top 4 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vim mapping for sorting a range of text

Sort Motion.vim

This plugin provides the ability to sort in Vim using text objects and motions. Sorting lines and argument lists manually can be a hassle, and thus most write it off as a waste of effort, but when its as easy as anything else in Vim, it becomes a viable option.

sort-motion has three different sorting modes:

  • Linewise: sort a sequence of lines (require statements, gem lists, etc)
  • Character: sort a comma separated list (argument lists, attribute lists, etc)
  • Visual (linewise or normal): provided for continuity, similar to linewise
  • Block Visual: By default behaves the same as the other visual modes. Optionally, you can provide a specific sort command which you might use to sort by a column (example: Vissort)

Installation

Using Vundle:

" add this line to your ~/.vimrc
Bundle 'christoomey/vim-sort-motion'

then run :BundleInstall from within Vim.

Usage

Linewise

The primary interface to this plugin is via the gs mapping, for sorting based on a text object or motion. To use the mapping, type gs followed by a motion, ie 2j to sort down two lines.

Examples:

  • gs2j => Sort down two lines (current + 2 below)
  • gsip => Sort the current paragraph
  • gsii => Sort the current indentation level (requires text-obj-indent plugin)

Character

In addition, if the text object is within a line then sort-motion will attempt to sort the text as a comma separated list.

Examples:

gsi( => Sort within parenthesis. (b, c, a) would become (a, b, c)

Visual

For continuity, sort-motion also defines a visual mode mapping for gs. This behaves as a linewise sort over the lines defined by the visual selection.

You can also (optionally) specify a blockwise command to use for block selections (example: Vissort).

Configuration

sort_motion_flags

If you'd like to pass any options to sort you can set g:sort_motion_flags. For example you could use:

let g:sort_motion_flags = 'ui'

To make all sorts case insensitive and remove duplicates.

Note: this only applies to linewise sorting (including visual), but does not apply to the character based sorting of comma separated lists.

sort_motion_visual_block_command

If you'd like to specify a specific command to use for blockwise selections you can set it here. This is useful if for example you want to use Vissort so that you can sort by a column.

let g:sort_motion_visual_block_command = 'Vissort'

By default the command used is sort.

NOTE: To use Vissort you will need to install this plugin.

More Repositories

1

vim-tmux-navigator

Seamless navigation between tmux panes and vim splits
Vim Script
5,206
star
2

dotfiles

My vim, zsh, git, tmux, and other config files and utility scripts.
Shell
466
star
3

vim-system-copy

Vim plugin for copying to the system clipboard with text-objects and motions
Vim Script
345
star
4

vim-tmux-runner

Vim and tmux, sittin' in a tree...
Vim Script
290
star
5

vim-conflicted

Easy git merge conflict resolution in Vim
Vim Script
271
star
6

your-first-vim-plugin

Samples and notes for my Aug 2014 'Your First Vim Plugin' talk
Vim Script
129
star
7

vim-titlecase

Teach Vim about titlecase, with support for motions and text objects
Vim Script
103
star
8

vim-quicklink

A Vim plugin for quickly looking up a topic in google and inserting the relevant link
Vim Script
55
star
9

boston-react-conf-2018-graphql-talk

Sample repo for my Boston React Conf 2018 talk on React & GraphQL
JavaScript
31
star
10

vim-run-interactive

Vim plugin to run shell commands in an interactive shell
Vim Script
26
star
11

vim-rfactory

Vim plugin for rapid navigation to FactoryBot factory definition
Ruby
23
star
12

display-table-summary

Vim Script
8
star
13

vim-presentation-mode

Vim Script
8
star
14

vim-textobj-codeblock

Vim Script
7
star
15

alfred-trello-boards

Alfred workflow for quick navigation to Trello boards
Ruby
7
star
16

vim-kata-meetup

Support repo for 2012-11-12 Boston Vim meetup
Ruby
5
star
17

ctrlp-generic

A generic list selection extension to CtrlP for vim
Vim Script
4
star
18

magictags

Automatic generation of tags file from Vim
Vim Script
4
star
19

vim-g-dot

Vim command to repeat last change over a number of lines
Vim Script
4
star
20

typescript-intro-presentation

3
star
21

live-down

Markdown rendering and live-reloading
3
star
22

conway

jQuery & coffeescript implementation of Conway's Game of Life
CoffeeScript
3
star
23

vim-colors-ctoomey

My colorschemes for vim
Vim Script
3
star
24

react-native-graphql

JavaScript
2
star
25

emit

Fun with canvas animation
Ruby
2
star
26

zero

A web app to monitor your inbox zero status over time
Ruby
2
star
27

elm-reaction

Elm
1
star
28

gsub.vim

Vim Script
1
star
29

inertia-svelte-repro

Ruby
1
star
30

vim-swiki

Vim plugin for simple wiki management
Vim Script
1
star
31

trusted-local

Vim Script
1
star