Skip to content

Latest commit

 

History

History
134 lines (96 loc) · 2.7 KB

README.adoc

File metadata and controls

134 lines (96 loc) · 2.7 KB

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