Coder Social home page Coder Social logo

vim-evalvim's Introduction

Eval Vim language

UPD

Vim9 has updated source command that can source not only the file but buffer lines, in a simplest form it is just a :source to evaluate whole buffer, :.source to evaluate current line.

Thus, simplified version of this plugin could be put into your .vimrc:

vim9script
# source vimscript (operator)
def SourceVim(...args: list<any>): any
    if len(args) == 0
        &opfunc = matchstr(expand('<stack>'), '[^. ]*\ze[')
        return 'g@'
    endif
    if getline(1) =~ '^vim9script$'
        vim9cmd :'[,']source
    else
        :'[,']source
    endif
    return ''
enddef
nnoremap <silent> <expr> <space>v SourceVim()
xnoremap <silent> <expr> <space>v SourceVim()
nnoremap <silent> <expr> <space>vv SourceVim() .. '_'

Run vimscript from anywhere in vim and save output to * (clipboard) register.

97157700 7c66c380 1789 11eb 9eb6 2148f01a32e3

Installation

minpac

somewhere in .vimrc
call minpac#init()
" ...
" more plugins
" ...
call minpac#add('habamax/vim-evalvim')

Then :call minpac#update() to install it.

vim-plug

somewhere in .vimrc
call plug#begin('~/.vim/plugged')
" ...
" more plugins
" ...
Plug 'habamax/vim-evalvim'

call plug#end()

Then :PlugInstall to install it.

Usage

There are no default mappings, add your own, for example:

xmap <leader>v <Plug>(EvalVim)
nmap <leader>v <Plug>(EvalVim)
omap <leader>v <Plug>(EvalVim)
nmap <leader>vv <Plug>(EvalVimLine)

Then having somewhere in your buffer add:

echo "hello world"
  • <leader>vv to evaluate current line

  • You should see hello world printed below

fun! TestFun(p)
    return a:p
endfun
echomsg TestFun("Another Hello!")
  • <leader>vip to evaluate current paragraph

  • You should see Another Hello printed below

Note
You can also visually select text block and evaluate it with <leader>v. Although you will not see the message printed — you can find it in :messages.
set nu!
set cursorline!
set cursorcolumn!
  • <leader>vip to evaluate current paragraph of settings

  • line numbers, cursorline and cursorcolumns will be toggled

Settings

By default all output is captured to * and " registers so you can paste it when needed.

To turn it off use:

let g:evalvim_capture_output = 0

vim-evalvim's People

Contributors

habamax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gorban

vim-evalvim's Issues

Multiline execution fails on unterminated quotes

Issue running commands with multiline strings. Issue occurs regardless of single or double quotes.

Tested with keybindings as listed in the README.md, #Usage:
  <leader>vap - Run this plugin with all the current paragraph

Content in Vim buffer:

echo "line 1
line 2
line 3"

Expected result:

line 1
line 2
line 3

Actual result is an Error:

Error detected while processing function evalvim#run:
line   32:
E114: Missing double quote: "line 1

For comparison running directly in terminal works as expected:

bash -c 'echo "line 1
line 2
line 3" '

I am on evalvim.vim,

Version:      1.0

:version

VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Mar 21 2024 12:49:18)
macOS version - x86_64
Included patches: 1-193
...
Huge version without GUI.
...

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.