All Projects → preservim → vim-textobj-sentence

preservim / vim-textobj-sentence

Licence: other
Improving on Vim's native sentence text object and motion

Programming Languages

Vim Script
2826 projects
shell
77523 projects

Projects that are alternatives of or similar to vim-textobj-sentence

vim-textobj-quote
Use ‘curly’ quote characters in Vim
Stars: ✭ 112 (+21.74%)
Mutual labels:  vim-plugin, writing, prose, vim-textobj-user
vim-colors-pencil
Light (& dark) color scheme inspired by iA Writer
Stars: ✭ 564 (+513.04%)
Mutual labels:  vim-plugin, writing, prose
vim-wordy
Uncover usage problems in your writing
Stars: ✭ 677 (+635.87%)
Mutual labels:  vim-plugin, writing, prose
Vim Wordy
Uncover usage problems in your writing
Stars: ✭ 645 (+601.09%)
Mutual labels:  vim-plugin, writing
Vim Colors Pencil
Light (& dark) color scheme inspired by iA Writer
Stars: ✭ 498 (+441.3%)
Mutual labels:  vim-plugin, writing
Vim Pencil
Rethinking Vim as a tool for writing
Stars: ✭ 1,186 (+1189.13%)
Mutual labels:  vim-plugin, writing
Vim Litecorrect
Lightweight auto-correction for Vim
Stars: ✭ 77 (-16.3%)
Mutual labels:  vim-plugin, writing
Vim Lexical
Build on Vim’s spell/thes/dict completion
Stars: ✭ 223 (+142.39%)
Mutual labels:  vim-plugin, writing
hlyank.vim
Highlight yanked text in Vim
Stars: ✭ 14 (-84.78%)
Mutual labels:  vim-plugin
notoire
A vim plugin to take notes using the Zettelkasten method
Stars: ✭ 53 (-42.39%)
Mutual labels:  vim-plugin
content-o-tron
A process for helping the Rust community and new comers to share their story of using Rust 🤖
Stars: ✭ 18 (-80.43%)
Mutual labels:  writing
perl-support
Edit Perl scripts in Vim/gVim. Insert code snippets, run, check, and profile the code and look up help.
Stars: ✭ 23 (-75%)
Mutual labels:  vim-plugin
dillinger
The last Markdown editor, ever.
Stars: ✭ 7,533 (+8088.04%)
Mutual labels:  writing
vim-log-highlighting
Syntax highlighting for generic log files in VIM
Stars: ✭ 164 (+78.26%)
Mutual labels:  vim-plugin
dps-ghosttext.vim
GhostText plugin powered by denops.vim
Stars: ✭ 20 (-78.26%)
Mutual labels:  vim-plugin
beacon.nvim
Whenever cursor jumps some distance or moves between windows, it will flash so you can see where it is
Stars: ✭ 217 (+135.87%)
Mutual labels:  vim-plugin
vim-multiselect
A library plugin to handle multiple visual selections
Stars: ✭ 27 (-70.65%)
Mutual labels:  vim-plugin
code runner.nvim
Neovim plugin.The best code runner you could have, it is like the one in vscode but with super powers, it manages projects like in intellij but without being slow
Stars: ✭ 234 (+154.35%)
Mutual labels:  vim-plugin
leximaven
A command line tool for searching word-related APIs.
Stars: ✭ 20 (-78.26%)
Mutual labels:  prose
vim-lineletters
because letters are easier to touch type than numbers
Stars: ✭ 38 (-58.7%)
Mutual labels:  vim-plugin

vim-textobj-sentence

Improving on Vim's native sentence text object and motion

Detecting sentences can be tricky, esp. when the words and punctuation of a sentence are interspersed with abbreviations, “quotations,” (parentheses), [brackets], the __markup__ from **lightweight** markup languages, and hard
line
breaks.

While Vim’s native sentence text object is quite capable, its behavior remains hard-coded and cannot be extended. Thus arises the need for a specialized text object offered by this plugin.

Features of this plugin:

  • Sophisticated sentence text object, supporting selection, motion, and jump
  • Implemented with regular expressions via the vim-textobj-user plugin
  • Supports sentences containing common abbreviations (configurable)
  • Support for sentences containing typographical characters, incl. quotes, em dash, etc.
  • Support for lightweight markup languages (markdown, e.g.)
  • Buffer scoped configuration

Installation

You can install using your favorite Vim package manager. (E.g., Pathogen, Vundle, or Plug.) If you are using a recent version of vim or neovim, you can also use native package support. (See :help packages.)

This plugin has an essential dependency that you will need to install:

Configuration

Because prose benefits more than code from a sentence text object, the behavior of this plugin can be configured per file type. For example, to enable sentence in markdown and textile files, place in your .vimrc:

set nocompatible            " this may already be in your .vimrc
filetype plugin indent on   " ...and this too

augroup textobj_sentence
  autocmd!
  autocmd FileType markdown call textobj#sentence#init()
  autocmd FileType textile call textobj#sentence#init()
augroup END

Decimal numbers and abbreviations

Though the period . glyph/character will normally terminate a sentence, it also has other uses. For example, the same glyph is used in abbreviations like ‘M.D.’ for Medical Doctor. These abbreviations, however, should be tolerated when detecting the boundaries of a sentence. The following should be considered one text object, rather than four:

Magnum, P.I. lives at Robin’s Nest, located at 11435 18th Ave., Oahu, HI.

This plugin detects decimal numbers and common abbreviations. By default, the following abbreviations will be recognized:

  let g:textobj#sentence#abbreviations = [
    \ '[ABCDIMPSUabcdegimpsv]',
    \ 'l[ab]', '[eRr]d', 'Ph', '[Ccp]l', '[Lli]n', '[cn]o',
    \ '[Oe]p', '[DJMSh]r', '[MVv]s', '[CFMPScfpw]t',
    \ 'alt', '[Ee]tc', 'div', 'es[pt]', '[Ll]td', 'min',
    \ '[MD]rs', '[Aa]pt', '[Aa]ve?', '[Ss]tr?',
    \ '[Aa]ssn', '[Bb]lvd', '[Dd]ept', 'incl', 'Inst', 'Prof', 'Univ',
    \ ]

Note that you can override/modify the above defaults in your .vimrc, but be sure to include the declaration before your call to textobj#sentence#init().

Motion commands

Motion commands on text objects are a powerful feature of Vim.

This plugin overrides Vim’s native commands for sentence selection:

  • as - select ‘around’ sentence with trailing whitespace

  • is - select ‘inside’ sentence without trailing whitespace

  • ( - move to start of previous sentence

  • ) - move to start of next sentence

This plugin adds:

  • g) - jump to end of current sentence
  • g( - jump to end of previous sentence

You can manipulate text just as with Vim’s original as and is commands, such as cis for change, vas for visual selection, das for deletion, yas for yanking to clipboard, etc.. Note that count isn’t supported at present (due to limitations of the underlying vim-textobj-user) but repeat with . does work.

If you prefer to retain the native commands, you can assign other key mappings via your .vimrc:

let g:textobj#sentence#select = 's'
let g:textobj#sentence#move_p = '('
let g:textobj#sentence#move_n = ')'

See also

If you find this plugin useful, check out these others originally by @reedes:

Future development

If you’ve spotted a problem or have an idea on improving this plugin, please post it to the GitHub project issue page.

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