1

Edit a python file with vim adddf.py, and type vert term and python3, there are two windows in vim.

cat adddf.py
def add_df(df,number):
    import re
    new_df = pd.DataFrame()
    nrow = df.shape[0]
    ncol = df.shape[1]
    for i in range(0,nrow):
        for j in range(0,ncol):
            new_df.at[i,j] =  df.iloc[i,j] + number
    return new_df

I want to copy some lines and execute it in left window, write a function:

function! CopyRun(start,stop)
    normal a:start,a:stop y+
    wincmd p
    call feedkeys("\<C-W>\"+")
endfunction

When I call it with:

call CopyRun(1,9)

I get the following output

enter image description here

  1. Nothing executed in python terminal,and nothing in + register
  2. the previous python function changed into below:
    d:start:stop y+ef add_df(df,number):
        import re
        new_df = pd.DataFrame()
        nrow = df.shape[0]
        ncol = df.shape[1]
        for i in range(0,nrow):
            for j in range(0,ncol):
                new_df.at[i,j] =  df.iloc[i,j] + number
        return new_df
  1. in bottom left, it says: emmet#anchorizeURL(0)

After following the answer from Maxim Kim in my .vimrc.
enter image description here

I get a new issue :

exe "normal! " . a:start . "," . a:stop . "y+"  

How to fix it?

1
  1. Check if your vim supports + register, :version output should include +clipboard. I would suggest to use other registers for that.

  2. Your normal command is wrong. Try smth like:

function! CopyRun(start,stop)
    " This would still not work as normal commands do not take range as ex commands...
    exe "normal! " . a:start . "," . a:stop . "y+"
    wincmd p
    call feedkeys("\<C-W>\"+")
endfunction

In your case with normal you literally run a then : then s etc. Here :execute helps with running a string as a vim command so you can construct your command with string concatenation (or with printf()).

It says emmet...something because you have used normal without ! mark meaning every letter might be remapped as happened here where your emmet plugin has been triggered.

PS

You can also check the source of https://github.com/habamax/vim-sendtoterm plugin.

PPS

better use :yank command (:h yank)

function! CopyRun(start,stop)
    exe a:start . "," . a:stop ."yank +"
    wincmd p
    call feedkeys("\<C-W>\"+")
endfunction

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.