Skip to content

(neo)vim text object for selecting top-level blocks in any programming language

License

Notifications You must be signed in to change notification settings

adolenc/vim-textobj-toplevel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vim-textobj-toplevel

Build Status MIT licensed

vim-textobj-toplevel is a (neo)vim plugin defining a new textobject: 'top-level block', bound to T by default. It is great for sending pieces of code to a REPL, or moving logical chunks of code around the file in arbitrary programming language.

Example

Consider the following example, a mix between dummy Python and C code. The lines on the left-hand side represent the code selected by aT and iT bindings:

aT iT
┌  ┌  @cache
│  │  def fn(c):
│  │  
│  │      if c > 3:
│  │          print('over 3')
│  │  
│  └      print('not over 3')
└     
┌  ┌  int fn2(int a,
│  │          int b)
│  │  {
│  │      int c = a + b;
│  │  
│  │      return c * 3;
│  └  } // part of top-level block because line above is not blank
│     
└     
┌  ┌  c = fn2(1, 2)
└  └  fn(c)

Intuitively a top-level block can be thought of as a paragraph that takes indentation into account: a new top-level block starts at the first non-indented line following a blank line, and spans all the lines until the next top-level block. In most ('nicely' formatted) source files this covers definitions of functions, classes, include statements, individual assignments and invocations at top level, etc.

vim-textobj-toplevel tries to mimic the built-in paragraph text object, with iT selecting the top-level block from anywhere within it, and aT selecting the top-level block and the trailing blank lines.

Installation

This plugin depends on Kana's vim-textobj-user. If you are using vim-plug, add following lines to your vimrc:

Plug 'adolenc/vim-textobj-toplevel' | Plug 'kana/vim-textobj-user'

About

(neo)vim text object for selecting top-level blocks in any programming language

Topics

Resources

License

Stars

Watchers

Forks