Giter Club home page Giter Club logo

enwise's Introduction

enwise

A vim plugin that allows you to use Enter key to close unbalanced brackets.

I always feel a bit awkward when using auto-pairing plugins in Vim. The auto-generated closing brackets not only save no keystrokes (advancing past the closing brackets requires typing the same keys), but also cause a lot of distractions when coding. What enwise does is simple: it keeps your currently-typing lines untouched, but will close any unbalanced brackets after you have pressed the Enter key, so you gain the advantages of auto-pairing and eyes-concentration.

Installation

Install enwise with your favorite plugin manager, e.g vim-plug:

Plug 'mapkts/enwise'

or install manually by coping this repo to ~/.vim/pack/vendor/start/ (Vim 8+ only).

Features

  • Free you mind from closing unbalanced brackets { ( [.
  • Respect your tab size and space size when inserting newline.
  • Smart enough to escape brackets inside quoted string.
  • Behave soundly when you press enter in the middle of a line.
  • Brackets inside comments like // { /* { */ are normally escaped.

Examples

  • Write a line of code from left to right ( | stands for cursor position )

before

sort_by('hello', function (x) {|

after

sort_by('hello', function (x) {
  |
})
  • Brackets inside quoted string are automatically escaped

before

println!("brackets: {{([ {} {}"|

after

println!("brackets: {{([ {} {}"
    |
)
  • Press enter inside non-eol brackets will push contents after the cursor down two lines

before

sort_by('hello', function (x) {|})

after

sort_by('hello', function (x) {
  |
})
  • Brackets inside comments will also be escaped

before

// {([|

after

// {([
// |

before

/*
 * {([|

after

/*
 * {([
 * |

Customization

  • enwise only closes brackets for a list of supported languages (see here). In order to bypass this limitation, put let g:enwise_enable_globally = 1 in your vimrc to enable it globally.
  • By default this plugin takes control of the enter key if <CR> hasn't been mapped yet. If you want to overload the enter key, put let g:enwise_disable_mappings = 1 in your vimrc before creating a conditional mapping. e.g.:
" Use <CR> to navigate completion menu (if pumvisible) or close brackets.
imap <silent><expr> <CR> pumvisible() ? "\<C-N>" : "\<CR>\<Plug>(EnwiseClose)"
  • Calling :EnwiseToggle will toggle enwise on and off. You might want to temporarily disable this plugin when writing some syntax extension code (e.g. Rust macros). Note that you can create a mapping for this command like so:
nnoremap <leader>te :EnwiseToggle<CR>
  • Put let g:enwise_auto_semicolon = 1 in your vimrc to allow enwise inserts needed semicolons after brackets when you hit Enter. This is a experimental feature currently.

Bug Report

Currently the languages enwise supported is limited. If you have encountered any bugs or inconvenience when using this plugin, please don't hesitate to open a issue.

enwise's People

Contributors

imgbotapp avatar jonz94 avatar mapkts avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

enwise's Issues

Enwise don't work until toggle it 2 times at start up.

The Enwise don't work with my vim as start up time. Even I've checked the Enwise having enabled by default, I have to call ":EnwiseToggle" 2 time to make it work as normal.

Here some of my system info:

Vim 8.2 patch 1-2846
Kitty_Terminal
OS: MX Linux KDE v19

CRLF cause plugin not work on macOS/Linux environment

First of all, thanks for creating this amazing plugin ๐Ÿ‘.
Your idea of only add missing pair after pressing Enter is so brilliant and mind blowing for me ๐Ÿ˜‚.

I currently have an issue when using this plugin on macOS or Linux environment. I got this error message whenever I open vim:

Error detected while processing /home/jonz94/.local/share/nvim/plugged/enwise/plugin/enwise.vim:
line    1:
E15: Invalid expression: !get(g:, "enwise_enable_globally")^M
line   42:
E171: Missing :endif

I think the issue is cause by CRLF (show as ^M in the error message), and could be solved by changing CRLF to LF.

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.