GithubHelp home page GithubHelp logo

snippets.nvim's People

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

snippets.nvim's Issues

Basic setup documentation

Hi,

Thank you for making this plugin. It looks extremely awesome. Is there documentation somewhere for a very basic setup? I have never used a lua plugin before, so I have a hard time connecting the dot between the install of the plugin and the definition of snippets in lua, both in the README. Should the lua code go in a separate file or how does that work?

If you have an example or could point me in the right direction, I would be happy to create a pull request with an updated README (if you find it valuable).

Thanks again for making this! I cannot wait getting started creating some neat python snippets

not placing the cursor in the right place with multi line snippets with white space before the snippet

not placing the cursor in the right place with multi line snippets with white space before the snippet

my snippet

local match_indentation = require'snippets.utils'.match_indentation

require'snippets'.snippets = {
    lua = {
        ["func"] = match_indentation "function $0()\n\nend"
}

cursor = ﱢ
Example with no space before

func<tab>

-- output

function ﱢ()

end

cursor = ﱢ
Example with one space before snippet

 func<tab>

-- output

 functionﱢ ()

 end

cursor = ﱢ
Example with function in function

function This_is_a_example()
    func<tab>
end

-- output

function This_is_a_example()
    function ()
    
    end
end

[suggestion] switch the use of <C-k> and <C-j

Not sure whether this is still active, but if yes it may be a good idea to switch the use of and as default mappings. should be associated with a "downwards" movement, which should pick "next" item.

Feature request - "regular" inserter

When using snippets.nvim to expand/complete LSP snippets, it would be helpful to have autocomplete, further snippets and other features related to the current buffer where the snip was called from.
This is not possible of course when using floaty ux inserter or vim input inserter as they are not expanded in the current buffer.

So the feature is, could there be a possibility of and an inserter for expanding the snippets in the current buffer, much like UltiSnips/vim-vsnip etc?

Integration with nvim-compe

Currently nvim-compe has an example of how it can be used with vsnip:

local t = function(str)
  return vim.api.nvim_replace_termcodes(str, true, true, true)
end

local check_back_space = function()
    local col = vim.fn.col('.') - 1
    return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil
end

-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
  if vim.fn.pumvisible() == 1 then
    return t "<C-n>"
  elseif vim.fn['vsnip#available'](1) == 1 then
    return t "<Plug>(vsnip-expand-or-jump)"
  elseif check_back_space() then
    return t "<Tab>"
  else
    return vim.fn['compe#complete']()
  end
end
_G.s_tab_complete = function()
  if vim.fn.pumvisible() == 1 then
    return t "<C-p>"
  elseif vim.fn['vsnip#jumpable'](-1) == 1 then
    return t "<Plug>(vsnip-jump-prev)"
  else
    -- If <S-Tab> is not working in your terminal, change it to <C-h>
    return t "<S-Tab>"
  end
end

Is there an easy easy way to use snippets.nvim here? I'm especially unsure of what the equivalent to vsnip#available is.

Thanks!

In-word expansion (equivalent to Ultisnips `i`)

I'm not sure whether this is already possible. If so, then this is a question about how to do it; if it isn't possible, it's a suggestion for a new feature.

Ultisnips allows in-word expansion. Here's how they describe it:

i In-word expansion - By default a snippet is expanded only if the tab
trigger is the first word on the line or is preceded by one or more
whitespace characters. A snippet with this option is expanded
regardless of the preceding character. In other words, the snippet can
be triggered in the middle of a word.

I use this a lot to insert comments in markdown files. For instance I will write This is a randomcm and then expand the cm snippet to get This is a random<!-- comment here -->. It would be great if I could do the same in snippets.nvim!

Autoexpand

Hi, do you have any plans to implement a feature for automatically expanding snippets? For example, snippet cl would automatically convert to class <HereAutomaticallyObtainedClassNameFromFileName>.

Questions on snippets and completion with completion-nvim

I have a couple things I would like to do with snippets nvim

  1. Organize snippets in another directory and preferably be able to lazy load based on filetype
     .
    ├─ lua
    │  ├─ init.lua
    │  └─ plugins 
    │     ├─ init.lua
    │     └─ snippets
    │        ├─ init.lua
    │        └─ lang            # Language directory
    │            ├─ c.lua       # C snippets
    │            └─ rust.lua    # Rust snippets
    └ init.vim
  1. When snippets get selected from completion-nvim expand (and maybe map to expansion to / without interfering with mapping to pumvisible menu selection if that's possible)

[Q] Reloading snippets?

Hello! Thanks for making this awesome plugin. It's really solid!
I was wondering if it is possible to reload a snippets file without restarting nvim?

This happens automatically in UltiSnips when you change snippets and I should think that reloading the snippets in nvim using eg :lua require('file_containing_snippets') would do the trick but it doesn't really. (this file contains the require'snippets'.snippets = {...snippets} stuff.

Any pointers are much appreciated!

Thanks

match_indentation

Thanks for a nice snippet plugin! I use it every day in lua and especially on dynamic languages like supercollider. Its really fantastic for wrapping registers in other code etc.

but.
I cant get match_indentation to work with the following type of snippet.

local U = require'snippets.utils'
require'snippets'.snippets = {
    lua = {
        ["for"] = U.match_indentation [[
        for ${1:i}, ${2:v} in ipairs(${3:t}) do
        $0
        end]];
    };
}

this always results in a lua for loop placed with the same amount of tabs/spaces that was present in the snippet file where it was defined. hope this makes sense :)

Am I doing something wrong or misunderstanding the use of require'snippets.utils'.match_indentation or is it broken?

Placeholders: use select mode

When UltiSnips jumps to a placeholder with optional text (${1:foo}), the text is selected in select mode (:h select-mode); this way one can just start typing to replace the placeholder text (or deleting by pressing backspace).

(Feel free to close or mark as later if this requires or is much easier with extmarks.)

Support transformations in placeholders

UltiSnips allows specifying transformations in placeholders. For example, ${1/foo/bar} inserts the text entered for $1 with foo replaced by bar. It also allows for regexes, so rather complicated transformations are possible. (For example, adding optional comment lines for parameters.)

Specifically, I would be interested in this for the purpose of having conditional text in snippets, where parentheses are omitted if the placeholder for the argument is left empty. E.g., im TeX, I could have a \usepackage[$2]{$1} snippet, which prints \usepackage[bar]{foo} if I enter bar for $2, but only \usepackage{$1} if $2 is left empty.

I think the simplest (in the sense of requiring the least special syntax) would be a way to inject a lua function into the snippet that gets fed the entered text (and possibly some context) and returns the transformed string that is then inserted into the expanded snippet. This would also need some way of specifying the text and cursor position shown before the placeholder text is entered (the [] above).
Maybe something like

\\usepackage${2:[2]|opt_or_nil}{$1}

where the part after : is shown upon expansion (and the 2 marks the location of the placeholder) and the typed text is piped into the function

local function opt_or_nil(s)
  if s == '' then 
    return ''
 else
   return '['..s..']'
 end
end

(Feel free to close or mark as later if this requires or is much easier with extmarks.)

Better control of word boundary behavior / add an equivalent of UltiSnips's `w`

If I have a snippet \phi which expands to φ, there should be a way to tell snippets.nvim how to handle word boundaries.

Specifically, I want to have \phi expanded even when the cursor is at (\phi| -- whereas now, lua print(require'snippets'.lookup_snippet_at_cursor()) shows the initial ( gets chomped up as part of what is used to decide to expand.

In ultisnips, this behavior is configured per-snippet via the w flag.

CC @norcalli since @clason mentioned your GH notifications are being wonky.

[Q] How to lazy init time a snippet?

Hi snippet folks!

I would like to pass a number/string to a function called in a snippet. But within the snippet. So to say. Hope this makes sense.

Code is maybe clearer than me trying to explain what I want.

local format = string.format
F = {}

function F.randf_array(num)
    local list = ""
    local randnum = math.random(3,8)
    if num == nil then num = randnum end
    for i=1,num,1 do
        list = list .. tostring(math.random())
        if i < num then list = list .. ", " end
    end
    return format("[%s]", list)
end

snippets = {
    _global = {
           some = [[Some(${1|F.randf_array()}, ${2:inf})]]; -- fine, creating random size of array (3-8 random floats)
           fruit = [[Fruit(${1|F.randf_array(5)}, ${2:inf})]]; -- fine, creating array of size 5 with random floats
           -- here comes the pseudo code
           other = [[Other(${1|F.randf_array(${-1=vim.fn.input("how many random floats would you like? ")})}, ${2:inf})]]; -- not ok, failing
    };
}

I wonder how to do the thing I sketch out in the snippet other ?
And not necessarily with vim.fn.input I would rather just write ${1(require'snippets'.u.lazy_magic):20} .. :)
Something that makes the snippet wait until the value for the randf_array(num) function has been entered.
Preferably with an UX (user experience) similar to if it had been the first $ entry in the snippet (eg. $1)

any help much appreciated.

Error expanding snippet

Expanding a snippet gives an error in the floating window buffer

NVIM v0.6.0-dev+27-g27118c6eb
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az32-73
.../plugged/snippets.nvim/lua/snippets/inserters/floaty.lua:157: Vim(lua):E5108: 
Error executing lua ...onfig/nvim/plugged/nvim-lspconfig/lua/lspconfig/util.lua:170: bad argument #1 to 'fs_realpath' (string expected, got nil)

Peek 2021-07-09 09-21

Show tab-based mapping in the README

Hi! (Thanks for making this!)

Other snippets plugins often show a quick snippet (ugh no pun intended) for how to "smart-map" <Tab> to either expand, jump to next slot, or insert a tab key (or ideally trigger completion).

Usually involving e.g. coc#expandableOrJumpable() for coc-snippets, or similar for vsnip, etc.

I'm sure there's likely a way to do so with snippets.nvim -- may be nice to have it in the README.

(Happy to send a PR if/when I figure out how to do so by jumping into the source).

How can I add a value of placeholder as argument to function?

I have this function to capitalize the first letter of a word:

function titleCase(first, rest)
   return first:upper()..rest:lower()
end

And want to use this in my snippet:
Basically i want capitalize what I typed on first placeholder

  typescriptreact = {
    ["ush"] = [[
    const [${1}, ${=string.gsub($1, "(%a)([%w_']*)", titleCase)}] = useState(${3})
    ]]
  };

I'm very noob on lua so apologies if it's a dumb question, but I'm really struggle with this

[help] Custom Mapping with Fallback

I'd like to use tab and shfit+tab for mappings but still have tab enter a literal tab character when not in a snippet. Tried something like this, but I'm still a noob with lua

inoremap <expr> <Tab> luaeval('require"snippets.has_active_snippet()') ?
             \ lua require'snippets'.expand_or_advance(1) :
             \ "\<Tab>"

Indentation

Had a thought (not sure if this is how other snippet plugins do it) but you could call indentexpr maybe to see what the next indent should be on new lines? not sure if that would work though.

Leaving it here in case it's helpful (close if not)

Is it possible disable the mini buffer window that appears after expanding a snippet?

I would prefer if I could get the "regular" behaviour of most other snippet plugins, i.e. no mini window that appears after expanding a snippet as this plugin seems to do:

snippets.nvim

Is this possible? What is the advantage of the current behaviour? To me it looks really ugly. Am I missing something?

As an example of what I mean, this what UltiSnips looks like:

UltiSnips

Default mappings only works in first buffer opened by nvim

Hello

I noticed this strange bug.
If I add

require'snippets'.use_suggested_mappings(true)

to my vim config file, I am able to expand snippets perfectly fine using the default mappings (C-k for example) in the first buffer opened by my nvim instance. But if I :tabnew newfile.md then this new file does not seem to have access to those mappings.

The problem for me was solved when I manually defined key mappings. They seem to persist without problems.

Thanks again for this awesome plugin

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.