Giter Club home page Giter Club logo

vim-expand-region's Introduction

vim-expand-region

About

vim-expand-region is a Vim plugin that allows you to visually select increasingly larger regions of text using the same key combination. It is similar to features from other editors:

vim-expand-region

Installation

Install using Pathogen, Vundle, Neobundle, or your favorite Vim package manager.

Quick Start

Press + to expand the visual selection and _ to shrink it.

Mapping

Customize the key mapping if you don't like the default.

map K <Plug>(expand_region_expand)
map J <Plug>(expand_region_shrink)

Setting

Customize selected regions

The plugin uses your own text objects to determine the expansion. You can customize the text objects the plugin knows about with g:expand_region_text_objects.

" Default settings. (NOTE: Remove comments in dictionary before sourcing)
let g:expand_region_text_objects = {
      \ 'iw'  :0,
      \ 'iW'  :0,
      \ 'i"'  :0,
      \ 'i''' :0,
      \ 'i]'  :1, " Support nesting of square brackets
      \ 'ib'  :1, " Support nesting of parentheses
      \ 'iB'  :1, " Support nesting of braces
      \ 'il'  :0, " 'inside line'. Available through https://github.com/kana/vim-textobj-line
      \ 'ip'  :0,
      \ 'ie'  :0, " 'entire file'. Available through https://github.com/kana/vim-textobj-entire
      \ }

You can extend the global default dictionary by calling expand_region#custom_text_objects:

" Extend the global default (NOTE: Remove comments in dictionary before sourcing)
call expand_region#custom_text_objects({
      \ "\/\\n\\n\<CR>": 1, " Motions are supported as well. Here's a search motion that finds a blank line
      \ 'a]' :1, " Support nesting of 'around' brackets
      \ 'ab' :1, " Support nesting of 'around' parentheses
      \ 'aB' :1, " Support nesting of 'around' braces
      \ 'ii' :0, " 'inside indent'. Available through https://github.com/kana/vim-textobj-indent
      \ 'ai' :0, " 'around indent'. Available through https://github.com/kana/vim-textobj-indent
      \ })

You can further customize the text objects dictionary on a per filetype basis by defining global variables like g:expand_region_text_objects_{ft}.

" Use the following setting for ruby. (NOTE: Remove comments in dictionary  before sourcing)
let g:expand_region_text_objects_ruby = {
      \ 'im' :0, " 'inner method'. Available through https://github.com/vim-ruby/vim-ruby
      \ 'am' :0, " 'around method'. Available through https://github.com/vim-ruby/vim-ruby
      \ }

Note that this completely replaces the default dictionary. To extend the default on a per filetype basis, you can call expand_region#custom_text_objects by passing in the filetype in the first argument:

" Use the global default + the following for ruby
call expand_region#custom_text_objects('ruby', {
      \ 'im' :0,
      \ 'am' :0,
      \ })

Customize selection mode

By default, after an expansion, the plugin leaves you in visual mode. If your selectmode(h:selectmode)) contains cmd, then the plugin will respect that setting and leave you in select mode. If you don't have selectmode set, but would like to default the expansion in select mode, you can use the global setting below:

let g:expand_region_use_select_mode = 1

Bitdeli Badge

vim-expand-region's People

Contributors

bitdeli-chef avatar kljohann avatar terryma 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-expand-region's Issues

Problems with remapping keys

This is probably an issue with my configuration but I'm stumped.

I have installed the plugin via Vundle and remapped the expand and shrink functions using vmap
vmap v (expand_region_expand)
vmap (expand_region_shrink)

But now I get :call <SNR>7_NextTextObject('i') every time I try to expand the selected region. What am I doing wrong?

Proper settings for Python

Hello there,

Can someone help me & possibly add this to the documentation - what should be the proper settings for visual expansion in Python?

Right now does not respect indentation and the visual expanding is not always correct.

HTML/XML tags

Thanks for the great plugin!
It would be really cool if this worked with HTML/XML tags.
For example, if I have
<div id="foo"><span class=".bar">some content</span></div>
and the cursor is in "some content", it would cool if
pressing + selected the content
and pressing + again selected <span class=".bar">some content</span>
and pressing + again selected <div id="foo"><span class=".bar">some content</span></div>.
Have you seen anything that does this?

fine expanding

Often users want more fine control on text, currently it's not the case for vim-expand-region.

An example is:

/a/b/c-d/g-f

we often want to be able to expand to c-d or g-f

Quoted text not selected correctly

Hi,

I've been using this plugin for a while, and I like it very much.

When starting selection inside quoted text, I noticed that at the second selection action, the plugin selects outside of the quotes (space delimited text object), rather than the whole content, if the part selected at first is a word at the beginning or at the end of the quoted text.

Example:

if (method() == "some example text")

If I stand on the word text and select it, the next selection will select text"). The same happens for standing on some and selecting twice: "some will be selected.
The whole content of the quotes (some example text), without them, will be selected only on the third selection action.

Is this a bug, or the designed behavior?
For me it is more intuitive to have the whole content selected right after selecting either of the words in the quotes.

E119 after update

So today I updated all plugins.

When trying to expand region I am getting:

Error detected while processing function expand_region#next[1]..<SNR>57_expand_region[20]..<SNR>57_select_region:
line    2:
E119: Not enough arguments for function: targets#e

I use:

NVIM v0.2.3-dev
Build type: RelWithDebInfo
Lua 5.1
Compilation: /usr/bin/x86_64-linux-gnu-gcc -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/build/neovim-BZSxou/neovim-0.2.2ubuntu2+git201804092017-84bac9f-f2f288d/build/config -I/build/neovim-BZSxou/neovim-0.2.2ubuntu2+git201804092017-84bac9f-f2f288d/src -I/build/neovim-BZSxou/neovim-0.2.2ubuntu2+git201804092017-84bac9f-f2f288d/.deps/usr/include -I/usr/include -I/build/neovim-BZSxou/neovim-0.2.2ubuntu2+git201804092017-84bac9f-f2f288d/build/src/nvim/auto -I/build/neovim-BZSxou/neovim-0.2.2ubuntu2+git201804092017-84bac9f-f2f288d/build/include
Compiled by buildd@lcy01-amd64-019

Features: +acl +iconv +jemalloc +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Edit:

One of following fixed the issue:

pip3 install --upgrade neovim
gem install neovim

Should check whether new region includes cursor position

I noticed that some text objects can select unexpected regions. For example, put the following into a file:

index(list, '(')
empty(taginfo)

then put the cursor on top of empty and press vib. The parentheses on the first line should now be selected. This is obviously not useful for our case. So it would make sense to check whether the region candidates actually include the original cursor position before trying to use them.

keep jumplist unchanged

Avoid that the visual expansion mapping <Plug>(expand_region_expand) adds a mark to the jump list.

not working as expected

  1. When I press the first +, it selects the WHOLE WORD
  2. The second +, it selects the WHOLE PARAGRAPH
  3. Any + right after the 2nd one DOES NOT WORK AT ALL

Not compatible with neovim?

Hi,
Thanks for creating this tool. I've been using it for a long time.

I'm migrating over to neovim, and noticed that it doesn't work in my setup. Below are the relevant lines in my config:

call plug#begin(stdpath('config') . '/plugged')
Plug 'terryma/vim-expand-region'
call plug#end()

nnoremap <space> <Plug>(expand_region_expand)

I'm wondering whether it is known to be incompatible with neovim, or something is wrong with my setup?

Docs for zero vs one

Thanks for the great plugin — everything's working well so far.

One question — what do the 0 & 1 values mean in the mappings? Did I just miss something in the docs?

insert of keymap instead expanding/shringkin

instead of expanding / shrinking the selection, i get this inserted:

vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)

Ruby block objects

Thanks for this great plugin that I've just discovered.

Do you support ruby block objects provided by nelstrom/vim-textobj-rubyblock?

I tried using the following configuration:

call expand_region#custom_text_objects('ruby', {
       \ 'ir' :0,
       \ 'ar' :0,
       \ 'im' :0,
       \ 'am' :0,
       \ })

But it is not working.

First + sometimes shrinks selection

I saw a report of something similar (#3) but I'll open this separately anyway, since the other one is closed.

Here are some issues I'm seeing, using this code as an example:

call winrestview(s:candidates[s:cur_index].prev_winview)
  1. If the cursor is on the first character of winrestview, viw+ does not grow the selection beyond the initial word. If, however, the cursor is after the first character, viw+ seems to grow the selection. I can only reproduce this ~90% of the time, so it seems that there's some sort of a race going on.
  2. If I manually select winrestview(, hitting + actually shrinks the selection.

`+` should only ever expand selection

Right now, there are times when pressing + will shrink the left side of the selection to accomodate a larger selection on the right side:

[submodule "vim/bundle/vim-expand-region"]
    path = vim/bundle/vim-expand-region
    url = https://github.com/terryma/vim-expand-region.git

If you place the cursor on the second bundle and continue pressing +, the selection will large to expand on the left, then suddenly, the selection on the left will shrink in order to accomodate a larger selection on the right.

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.