All Projects → nelstrom → Vim Textobj Rubyblock

nelstrom / Vim Textobj Rubyblock

A custom text object for selecting ruby blocks.

Labels

Projects that are alternatives of or similar to Vim Textobj Rubyblock

Vim Smooth Scroll
Make scrolling in Vim more pleasant
Stars: ✭ 262 (-18.38%)
Mutual labels:  viml
Vim Powerline
Moved to powerline/powerline.
Stars: ✭ 2,880 (+797.2%)
Mutual labels:  viml
Vim Phpqa
PHP QA tools for Vim
Stars: ✭ 296 (-7.79%)
Mutual labels:  viml
Jshint2.vim
Lightweight, customizable and functional Vim plugin for JSHint integration.
Stars: ✭ 265 (-17.45%)
Mutual labels:  viml
Dotfiles
twerth
Stars: ✭ 274 (-14.64%)
Mutual labels:  viml
Investigate.vim
A Vim plugin for looking up documentation
Stars: ✭ 282 (-12.15%)
Mutual labels:  viml
File Line
Plugin for vim to enabling opening a file in a given line
Stars: ✭ 260 (-19%)
Mutual labels:  viml
Vim Dadbod Ui
Simple UI for https://github.com/tpope/vim-dadbod
Stars: ✭ 315 (-1.87%)
Mutual labels:  viml
Dotfiles
My config files
Stars: ✭ 276 (-14.02%)
Mutual labels:  viml
Blamer.nvim
A git blame plugin for neovim inspired by VS Code's GitLens plugin
Stars: ✭ 283 (-11.84%)
Mutual labels:  viml
Vim Tomorrow Theme
Tomorrow Theme for Vim
Stars: ✭ 269 (-16.2%)
Mutual labels:  viml
A.vim
Alternate Files quickly (.c --> .h etc)
Stars: ✭ 272 (-15.26%)
Mutual labels:  viml
Elm.vim
Vim plugin for the Elm programming language
Stars: ✭ 286 (-10.9%)
Mutual labels:  viml
Vim Language Server
VImScript language server, LSP for vim script
Stars: ✭ 264 (-17.76%)
Mutual labels:  viml
Vim Buffet
IDE-like Vim tabline
Stars: ✭ 304 (-5.3%)
Mutual labels:  viml
Vim Rubocop
The Vim RuboCop plugin runs RuboCop and displays the results in Vim
Stars: ✭ 262 (-18.38%)
Mutual labels:  viml
Vim Stylus
Syntax Highlighting for Stylus
Stars: ✭ 277 (-13.71%)
Mutual labels:  viml
Molokai
Molokai color scheme for Vim
Stars: ✭ 3,349 (+943.3%)
Mutual labels:  viml
Vim Config
my vim config to share amongst my machines
Stars: ✭ 312 (-2.8%)
Mutual labels:  viml
Rust.vim
Vim support for Rust file detection and syntax highlighting.
Stars: ✭ 288 (-10.28%)
Mutual labels:  viml

A custom text object for selecting ruby blocks.

Flattr this

Depends on Kana's textobj-user plugin. Test suite requires vspec (also by Kana).

Also requires that the matchit.vim plugin is enabled. Ensure that the following line is included somewhere in your vimrc file:

runtime macros/matchit.vim

It is also essential that you enable filetype plugins, and disable Vi compatible mode. Placing these lines in your vimrc file will do this:

set nocompatible
if has("autocmd")
  filetype indent plugin on
endif

Usage

When textobj-rubyblock is installed you will gain two new text objects, which are triggered by ar and ir respectively. These follow Vim convention, so that ar selects all of a ruby block, and ir selects the inner portion of a rubyblock.

In ruby, a block is always closed with the end keyword. Ruby blocks may be opened using one of several keywords, including module, class, def, if, unless and do. This example demonstrates a few of these:

module Foo
  class Bar
    def baz
      [1,2,3].each do |i|
        i + 1
      end
    end
  end
end

Suppose your cursor was positioned on the word def. Typing var would enable visual mode selecting all of the method definition. Your selection would comprise the following lines:

def baz
  [1,2,3].each do |i|
    i + 1
  end
end

Whereas if you typed vir, you would select everything inside of the method definition, which looks like this:

[1,2,3].each do |i|
  i + 1
end

Note that the ar and ir text objects always enable visual line mode, even if you were in visual character or block mode before you triggered the rubyblock text object.

Note too that the ar and ir text objects always position your cursor on the end keyword. If you want to move to the top of the selection, you can do so with the o key.

Limitations

Some text objects in Vim respond to a count. For example, the a{ text object will select all of the current {} delimited block, but if you prefix it with the number 2 (e.g. v2i{) then it will select all of the block that contains the current block. The rubyblock text object does not respond in this way if you prefix a count. This is due to a limitation in the textobj-user plugin.

However, you can achieve a similar effect by repeating the rubyblock text-object manually. So if you press var to select the current ruby block, you can expand your selection outwards by repeating ar, or contract your selection inwards by repeating ir.

Development

Running the specs

Set up the testing environment by running this command from the project root:

bundle install

Then you can run the tests with rake:

bundle exec rake test

Generating a vimball

To distribute the script on vim.org wrap it up as a vimball by following these steps:

  • open the file vimballer in Vim
  • set the variable g:vimball_home to the development directory of this plugin (e.g. run: :let g:vimball_home='~/dotfiles/vim/bundle/textobj-rubyblock')
  • visually select all lines in vimballer file
  • run '<,'>MkVimball! textobj-rubyblock.vba

That should create a file called textobj-rubyblock.vba which you can upload to vim.org.

Credits

This plugin was built by Drew Neil, but the real credit goes to Kana, whose textobj-user plugin provides a framework for building custom text objects. I couldn't have created the rubyblock plugin without building on top of his hard work, so I'd like to say a big thanks to Kana.

License

Copyright (c) Drew Neil. Distributed under the same terms as Vim itself. See :help license.

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].