Giter Club home page Giter Club logo

cobra's Introduction

coBra

๐Ÿ for [co]erced [bra]cket

A simple vim plugin that forces brackets and quotes to be smart.

Status update

Hi, I will no longer continue to maintain this plugin as I moved to nvim plus now I write my plugins in Lua. (Actually, I had planned to rewrite it completely in lua and using Treesitter requests, we'll see.)

install

If you use a plugin manager, follow the traditional way.

For example with vim-plug add this in .vimrc:

Plug 'doums/coBra'

Then run in vim:

:source $MYVIMRC
:PlugInstall

If you use vim package :h packages.

features

caption:
| = cursor or bounds of the selection in visual mode
* = a random character
n = end of line

mode before map after
close insert | [ [|]
delete insert [|] <BS> |
skip insert [|] ] [ ]|
break insert [|] <CR> [n|n]
wrap visual |****| <Leader>[ [|****|]
replace visual |[****]| <Leader>( (|****|)
skip on quotes visual |"****"| <Leader>" "|****|"

note: All maps works on multi lines. The presence of characters between the brackets or the quotes does not prevent maps from working.

settings

coBra runs in insert and visual modes only, default pairs are "'`{([.

coBra works by buffer and more precisely by file type. Be sure to have the filetype option on (you can check it with :filetype, and look for detection:ON). This way coBra uses the corresponding set of pairs if available (defined with g:coBraPairs). If not, he falls back to the default setting.

coBra maps for insert mode <BS>, <CR> and the two characters of each pair.
For visual mode one map for each opener characters prefixed by <Leader> is created.
He expects that no mapping for these keys already exists. If not, the concerned mapping will fail.

All settings are optional.

To customize the pairs use g:coBraPairs, if the open character is the same as the close character the pair is considered as quotes (different behavior on some situation compared to brackets). You have to enter a set of pairs by file type. Of course you can customize the default set too.

let g:coBraPairs = {
  \  'default': [
  \    ['"', '"'],
  \    ["'", "'"],
  \  ],
  \  'rust': [
  \    ['"', '"'],
  \    ['<', '>'],
  \    ['{', '}'],
  \    ['(', ')'],
  \    ['[', ']']
  \  ]
  \ }

Preformance is king when we type. For that reason you can set g:coBraMaxPendingCloseTry to a scpecific value between 0 and maxfuncdepth, default 10. When you type an openning bracket, before inserting and auto closing it the script looks recursively for a "pending" close bracket that does not have a matching open one. If it find one the script simply inserts the open bracket without auto closing it to complete the pair. g:coBraMaxPendingCloseTry limits the number of try of this logic.

let g:coBraMaxPendingCloseTry = 10

By default, and for the sake of performance, coBra takes into account only the visible lines from the current window. With this option you can configure coBra to run on the entire file.

let g:coBraFullBuffer

Like g:coBraFullBuffer but instead of the whole file, you can set a range of lines (starting from the cursor position, forward and backward).

let g:coBraLineMax = 10

license

Mozilla Public License 2.0

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.