All Projects → AndrewRadev → Sideways.vim

AndrewRadev / Sideways.vim

Licence: mit
A Vim plugin to move function arguments (and other delimited-by-something items) left and right.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Sideways.vim

Splitjoin.vim
Switch between single-line and multiline forms of code
Stars: ✭ 1,383 (+273.78%)
Mutual labels:  refactoring, vim-plugin
Rainbow levels.vim
A different approach to code highlighting.
Stars: ✭ 415 (+12.16%)
Mutual labels:  refactoring, vim-plugin
Switch.vim
A simple Vim plugin to switch segments of text with predefined replacements
Stars: ✭ 506 (+36.76%)
Mutual labels:  vim-plugin, cursor
Tagalong.vim
Change an HTML(ish) opening tag and take the closing one along as well
Stars: ✭ 184 (-50.27%)
Mutual labels:  refactoring, vim-plugin
Pear Tree
A Vim auto-pair plugin that supports multi-character pairs, intelligent matching, and more
Stars: ✭ 327 (-11.62%)
Mutual labels:  vim-plugin
Zeavim.vim
Zeal for Vim
Stars: ✭ 320 (-13.51%)
Mutual labels:  vim-plugin
Languageclient Neovim
Language Server Protocol (LSP) support for vim and neovim.
Stars: ✭ 3,352 (+805.95%)
Mutual labels:  vim-plugin
Awesome Minimalist
A curated list of awesome minimalist frameworks (simple and lightweight).
Stars: ✭ 3,189 (+761.89%)
Mutual labels:  lists
Spacevim
Spacemacs for vim
Stars: ✭ 366 (-1.08%)
Mutual labels:  vim-plugin
Vim Iced
Clojure Interactive Development Environment for Vim8/Neovim
Stars: ✭ 343 (-7.3%)
Mutual labels:  vim-plugin
Vim Crystal
Vim filetype and tools support for Crystal language.
Stars: ✭ 326 (-11.89%)
Mutual labels:  vim-plugin
Reorder python imports
Rewrites source to reorder python imports
Stars: ✭ 320 (-13.51%)
Mutual labels:  refactoring
Vim Template
Simple templates plugin for Vim
Stars: ✭ 328 (-11.35%)
Mutual labels:  vim-plugin
Awesome Wasi
😎 Curated list of awesome things regarding WebAssembly WASI ecosystem.
Stars: ✭ 319 (-13.78%)
Mutual labels:  lists
Sharpen
Visual Studio extension that intelligently introduces new C# features into your existing codebase
Stars: ✭ 351 (-5.14%)
Mutual labels:  refactoring
Emacs Refactor
language-specific refactoring in Emacs
Stars: ✭ 313 (-15.41%)
Mutual labels:  refactoring
Rigel
🌌 Colorscheme for vim, terminal, vscode and slack - based on the star Rigel ✨.
Stars: ✭ 324 (-12.43%)
Mutual labels:  vim-plugin
Indentline
A vim plugin to display the indention levels with thin vertical lines
Stars: ✭ 3,681 (+894.86%)
Mutual labels:  vim-plugin
Awesome Template Literal Types
Curated list of awesome Template Literal Types examples
Stars: ✭ 323 (-12.7%)
Mutual labels:  lists
React Native Input Scroll View
Perfect TextInput ScrollView
Stars: ✭ 323 (-12.7%)
Mutual labels:  cursor

Build Status

Usage

The plugin defines two commands, :SidewaysLeft and :SidewaysRight, which move the item under the cursor left or right, where an "item" is defined by a delimiter. As an example:

def function(one, two, three):
    pass

Placing the cursor on "two" and executing :SidewaysLeft, the "one" and "two" arguments will switch their places, resulting in this:

def function(two, one, three):
    pass

In this case, the delimiter is a comma. The plugin currently works with various other cases and it's intended to make the process configurable. While this particular example is in python, this should work for arguments in many different languages that use round braces to denote function calls.

For ruby and eruby, it detects method calls without braces as well:

link_to user_registration_path, 'Something'
# changes to:
link_to 'Something', user_registration_path

Apart from functions, it works for square-bracket lists in dynamic languages:

list = [one, [two, four, five], three]

If you experiment with this example, you'll find that you can move the entire second list around, as long as the cursor is on one of the inner brackets. The plugin takes into consideration nested structures.

It also works for multiline lists. Try experimenting with this example:

<div class="example"
     style="color: red;"
     something="other">
  Example
</div>

It's highly recommended to map the two main commands to convenient keys. For example, mapping them to <c-h> and <c-l> would look like this:

nnoremap <c-h> :SidewaysLeft<cr>
nnoremap <c-l> :SidewaysRight<cr>

The plugin also provides the commands :SidewaysJumpLeft and :SidewaysJumpRight, which move the cursor left and right by items.

Other things that sideways works for:

CSS declarations:

a { color: #fff; background: blue; text-decoration: underline; }

Lists within CSS declarations:

border-radius: 20px 0 0 20px;

HTML attributes:

<input name="one" id="two" class="three" />

Handlebars components:

{{parent/some-component one=two three="four" five=(action 'six')}}

Cucumber tables:

Examples:
  | input_1 | input_2 | button | output |
  | 20      | 30      | add    | 50     |
  | 2       | 5       | add    | 7      |
  | 0       | 40      | add    | 40     |

Rust template arguments:

let dict = Hash<String, Vec<String>>::new();

Rust return type (a special case since there's always just one, useful as a text object):

fn example() -> Result<String, String> {

Go lists:

[]string{"One", "Two", "Three"}

C++ templates:

/*
 * Relies on "<" being surrounded by non-whitespace, or considers it a
 * comparison. Parsing C++ is tricky.
 */
std::unordered_map<k, v>()

Javascript-like objects:

dict = {one: 1, two: 2, three: 3}

OCaml lists:

let xs = [1;2;3]

The plugin is intended to be customizable, though at this point you'd need to look at the source to do this.

Bonus functionality

Text objects

The plugin's machinery makes it easy to implement an "argument" text object. There are two mappings provided:

<Plug>SidewaysArgumentTextobjA
<Plug>SidewaysArgumentTextobjI

These are the outer and inner text objects, respectively. To use them, you need to create mappings in your configuration files. Something like this:

omap aa <Plug>SidewaysArgumentTextobjA
xmap aa <Plug>SidewaysArgumentTextobjA
omap ia <Plug>SidewaysArgumentTextobjI
xmap ia <Plug>SidewaysArgumentTextobjI

This will map the "a" text object to operate on an "argument". So, you can perform daa to delete an argument, cia to change an argument, and so on. See :help text-objects for more information.

Also, a useful plugin to use alongside sideways is fieldtrip. This defines a submode for sideways.vim.

Adding items

The plugin defines mappings to add new items to the list as well. There's four of them that mirror the i, a, I, and A built-in keybindings:

<Plug>SidewaysArgumentInsertBefore
<Plug>SidewaysArgumentAppendAfter
<Plug>SidewaysArgumentInsertFirst
<Plug>SidewaysArgumentAppendLast

However, they're not mapped by default and you need to pick ones that are convenient for you. As an example:

nmap <leader>si <Plug>SidewaysArgumentInsertBefore
nmap <leader>sa <Plug>SidewaysArgumentAppendAfter
nmap <leader>sI <Plug>SidewaysArgumentInsertFirst
nmap <leader>sA <Plug>SidewaysArgumentAppendLast

The mnemonic in this case would be leader-"sideways"-action. Given the following simple example in ruby:

function_call(one, two, three)

With the cursor on "two", you can insert a new argument before the current item by using <Plug>SidewaysArgumentInsertBefore:

function_call(one, NEW, two, three)

Add an item after the current one by using <Plug>SidewaysArgumentAppendAfter:

function_call(one, two, NEW, three)

Prepend an item to the start of the list with <Plug>SidewaysArgumentInsertFirst:

function_call(NEW, one, two, three)

Push an item at the end with <Plug>SidewaysArgumentAppendLast:

function_call(one, two, three, NEW)

This should work for all lists that are supported for the plugin, including HTML attributes, semicolon-separated CSS declarations, etc. If each existing list item is on a separate line (and there's at least two), the plugin assumes the new item should be on a new line as well:

function_call(
  one,
  two,
  three
)

# Append an item at the end:
function_call(
  one,
  two,
  three,
  NEW
)

Again, these mappings are not created by default -- copy the suggested ones to your vimrc, or create your own.

If you set g:sideways_add_item_cursor_restore to 1 and your vim has the +textprop feature, the plugin will jump back to where you triggered the mapping when you leave insert mode.

Note, however, that this relies on the InsertLeave autocommand, so if you exit insert mode via Ctrl+C (which doesn't trigger it), it won't jump until the next time you leave insert mode normally. If exiting via Ctrl+C is a part of your workflow, it's recommended you keep this setting off.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].