Code Monkey home page Code Monkey logo

nvim-editcommand's Introduction

nvim-editcommand

Edit your current shell command inside a scratch buffer.

nvim-editcommand provides similar functionality to fc or <c-x><c-e>/Ctrl-x,Ctrl-e, allowing the user to edit their current shell command in an editor.

The reason a user may want to do this is that it allows them to access the editors functionality that may not be available on the command line.

It also allows the user to edit command in shell's that may not otherwise provide the same functionality, e.g. python/ruby interpreters.

The command before and after editing can be accessed via the global variables g:editcommand_before and g:editcommand_after.

nvim-editcommand would be useful for a Neovim user who is running their shell inside a Neovim terminal buffer. In such a situation <c-x><c-e> is still available but (assuming your $EDITOR is nvim) it will have to open a new Neovim instance inside the terminal inside the existing Neovim instance, which can quickly become rather cumbersome to navigate in and out of.

Installation

call plug#begin('~/.nvim/plugged')
Plug 'brettanomyces/nvim-editcommand'
...
call plug#end()

Configuration

User should set g:editcommand_prompt to their shell prompt

let g:editcommand_prompt = '>'       " default is '$'

The default mapping is <c-x><c-e> however you may disable this mapping by setting

let g:editcommand_no_mappings = 1    " default is 0

To provide you own mapping provide a terminal mapping to <Plug>EditCommand

tmap <c-x> <Plug>EditCommand         " default is <c-x><c-e>

To use a temporary file rather than a scratch buffer set g:editcommand_use_temp_file

let g:editcommand_use_temp_file = 1  " default is 0

Notes

The scratch buffer cannot be saved, use :close or :bdelete or :quit.

If using a temporary file the command will only be copied back if you save first :wquit.

The command in the buffer will be saved to g:editcommand_after by an autocmd which then removes itself. When the terminal buffer is re-entered the command is copied to the commandline by another autocmd which also removes itself.

Feedback

Suggestions / Issues / Pullrequest are all very much welcome.

nvim-editcommand's People

Contributors

bnjmn avatar brettanomyces avatar wellle avatar

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

nvim-editcommand's Issues

prompt may change if user enters an interpreter

If a user enters a interpreter from within the terminal. e.g. python, then the prompt may change, $ -> >>>. We should provide a mechanism to automatically update the prompt, and reset the prompt, when the user leaves the interpreter.

To do this we could remap <cr> to run some commands if the current command is python/lua/ruby/etc.. and the same for whatever command is used to exit the interpreter. We will also need to handle the case where the user uses control characters, e.g. ^C, to leave the interpreter.

Method of clearing commandline is rather hacky

Because terminal buffers are 'nomodifiable' clearing the commandline after we have extracted the command is a bit of a hack.

The only way I've found that works is to have the keypresses required directly inside of the mapping (or having them inside a macro which is called directly from the mapping).

Extracting them into their own function does not work.
execute 'normal!...' does not work.
'feedkeys()' cannot be used because it does not run till the script has completed.

If we had the job id of the terminal then we could do call jobsend(id, "^C") but I'm unsure if terminals started using :terminal even get a job id.

call termopen('/usr/local/bin/fish') does return a job id so it could be used but then users would need to start their terminals via my plugin somehow, currently the plugin works regardless of how the terminal was started.

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.