Coder Social home page Coder Social logo

snip's Introduction

What's this?

Snip is a vim plugin for creating and managing vim abbreviations.

Installation

Your preferred plugin manager, e.g with Vim-Plug:

Plug "quintik/Snip"

Quick Start

Create a /snip directory in the same directory as $MYVIMRC, create a <filetype>.snip file within the snip directory and you can start adding snips to the file. For example, inside snip/java.snip:

# main #
snip psvm {
public static void main()<Left>
}

Then, inside a java file, type 0psvm and it will be expanded once you press space.

See :h snip for a more thorough introduction.

License

MIT License

snip's People

Contributors

mhmood-sf avatar

Stargazers

 avatar  avatar  avatar Yuta Katayama avatar Alex avatar Amelia Gapin avatar Bill Wadley avatar  avatar  avatar  avatar Easton Potokar avatar Theodore Felix Leo avatar Andy Shevchenko avatar

Watchers

 avatar

snip's Issues

Improve syntax highlighting

  • # breaks highlighting inside snip block (thinks it's a comment, but they're not allowed inside the block).
  • Curly braces shouldn't be highlighted the same as their contents.

That's all I can think of for now, might add more stuff later?

Add snips to completion list

As the title says, add snips to the completion list, based on which ones are activated in the current buffer. See :h completion-functions.

Allow snippets to include user input, prompted when the abbreviation is triggered

Rationale

So, snippets with multi-cursors or similar functionality seems to be tricky to do without adding a lot of complex code (at least from what i can tell?), so instead a simpler way is to trigger the abbreviation, leave input placeholders, and then prompt the user for what to replace the placeholders with. This sounds (and kind of is) a bit hacky, but seems to work smoothly enough, and can be refined further (suggestions at the end).

Example implementation

First, a SnipInput() function:

function! SnipInput()
    let s:placeholder = localtime() . localtime()
    return s:placeholder
endfunction

The placeholder needs to be a large and random enough string such that when it is replaced at the end, there's a near-zero chance of colliding with anything else in the buffer. An example (as shown above) is the current time in ms (repeated twice just in case).

Next, the prompt function:

function! SnipPrompt(prompt)
    let str = input(a:prompt)
    execute ":%s?" . s:placeholder . "?" . str . "?g"
    return ""
endfunction

Here we make use of :h input() and then execute a global substitute, replacing the placeholder with the input string and returning an empty string so nothing else is added to the abbreviation.

The abbreviation itself would look like:

inoreabbrev test
    \ \begin{<C-R>=SnipInput()<CR>}<CR>
    \ <CR>
    \ \end{<C-R>=SnipInput()<CR>}<CR>
    \ <C-R>=SnipPrompt("Environment: ")<CR>

Or in snip syntax:

snip test {
\begin{<C-R>=SnipInput()<CR>}<CR>
<CR>
\end{<C-R>=SnipInput()<CR>}<CR>
<C-R>=SnipPrompt("Environment: ")<CR>
}

UX improvements

Obviously, the input/prompt parts are quite unreadable. Since the input part is always constant, it would be easy to add a special keyword (for example, <INPUT>) which can be used in the snip file, and then later when the snippets are being registered it can be replaced with the actual expression. Something similar could be done with SnipPrompt, but it needs to be decided how to handle the prompt string. Maybe something like <PROMPT:Environment>? Spaces and nested colons might be tricky to handle depending on how this is parsed. Regardless, with these changes the syntax would look like:

snip test {
\begin{<INPUT>}<CR>
<CR>
\end{<INPUT>}<CR>
<PROMPT:Environment>
}

This is obviously much cleaner and readable (even more so with syntax highlighting, which isn't available here on GH ๐Ÿ™).

Improve parser

  • Fix the maxfuncdepth error somehow
  • Haven't taken a look at the parser's code for a while, but I think it could probably use some cleaning up.

I'll add more later, maybe.

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.