Coder Social home page Coder Social logo

attempt.nvim's Introduction

attempt.nvim

Manage your temporary buffers

Preview

preview

Features

  • Quickly create scratch files for any filetype, using vim.ui.select, vim.ui.input or any other method
  • Scratch files are saved in a temporary directory for later use, and can be accessed across neovim instances
  • Files are initialized with all the necessary boilerplate to be runnable
  • Reopen closed attempts with Telescope
  • Autosave attempts
  • Run the scratch files
  • Every file operation is asynchronous

Installation

This plugin is for neovim only. Version 0.7+ is required.

packer.nvim:

use {
  'm-demare/attempt.nvim',
  requires = 'nvim-lua/plenary.nvim',
}

-- Optional
use {
  { 'nvim-telescope/telescope.nvim' },
  { 'nvim-telescope/telescope-ui-select.nvim' }
}

vim-plug:

Plug 'nvim-lua/plenary.nvim'
Plug 'm-demare/attempt.nvim'

" Optional
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-ui-select.nvim'

Usage

If you are ok with the default settings:

require('attempt').setup()

To change them

require('attempt').setup{
  dir = (unix and '/tmp/' or vim.fn.expand '$TEMP\\') .. 'attempt.nvim' .. path_separator,
  autosave = false,
  list_buffers = false,     -- This will make them show on other pickers (like :Telescope buffers)
  initial_content = {
    py = initial_content_fn -- Either string or function that returns the initial content
    c = initial_content_fn,
    cpp = initial_content_fn,
    java = initial_content_fn,
    rs = initial_content_fn,
    go = initial_content_fn,
    sh = initial_content_fn
  },
  ext_options = { 'lua', 'js', 'py', 'cpp', 'c', '' },  -- Options to choose from
  format_opts = { [''] = '[None]' },                    -- How they'll look
  run = {
    py = 'w !python',       -- Either strings or lua functions
    js = 'w !node',
    lua = 'w | luafile %',
    sh = 'w !bash',
    pl = 'w !perl'
  }
}
-- (You may omit the settings whose defaults you're ok with)

Telescope picker

To use the telescope picker for opening your attempts (recommended, to have a nice previewer), add this somewhere after your telescope.setup() call:

require('telescope').load_extension 'attempt'

You can customize this picker in the usual telescope way

Keymaps

By default, no keymaps are created. To use the basic presets, you can do:

local attempt = require('attempt')

function M.map(mode, l, r, opts)
    opts = opts or {}
    opts = vim.tbl_extend('force', { silent=true }, opts)
    vim.keymap.set(mode, l, r, opts)
end

map('n', '<leader>an', attempt.new_select)        -- new attempt, selecting extension
map('n', '<leader>ai', attempt.new_input_ext)     -- new attempt, inputing extension
map('n', '<leader>ar', attempt.run)               -- run attempt
map('n', '<leader>ad', attempt.delete_buf)        -- delete attempt from current buffer
map('n', '<leader>ac', attempt.rename_buf)        -- rename attempt from current buffer
map('n', '<leader>al', 'Telescope attempt')       -- search through attempts
--or: map('n', '<leader>al', attempt.open_select) -- use ui.select instead of telescope

See :h attempt-interface for more customized setups

attempt.nvim's People

Contributors

chrsm avatar m-demare avatar

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.