1

what im trying to achieve:

  • use <C-V> to paste text in normal mode in current buffer
  • use same <C-V> to vertically split a file from nerdtree

what i know:

  • when you are with your cursor in nerdtree and you press the letter s, it will split the file under cursor vertically ( from docs: " s: open vsplit)

what i tried:

  • :normal s from nerdtree buffer, and it worked like a charm.

in init.vim i have this:

" this function works, i tried it many times
function IsCurrentWindowNERDTree()
  return exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) == winnr()
endfunction

function Control_v_key_binding()
    if IsCurrentWindowNERDTree()
        " problem is here !!!
        normal s
    else
        " this just pastes the text from os clipboard
        normal "+p 
    endif
endfunction

nnoremap <C-V> :call Control_v_key_binding()<CR>
inoremap <C-V> <C-O>:call Control_v_key_binding()<CR>

in function, i tried:

  • execute "normal \s"
  • normal \s
  • normal s

i mapped nnoremap <C-N> :normal s<CR> for control+N and it worked.

function Control_v_key_binding()
    if IsCurrentWindowNERDTree()
        normal s
    else
        normal "+p
    endif
endfunction

" this is really stupid, this configuration works flawlessly
nnoremap <C-N> :call Control_v_key_binding()<CR>

" and this doesnt work
nnoremap <C-V> :call Control_v_key_binding()<CR>

some weird part, i debugged this function and it just wont enter in the first if, goes automatically on else, but works on every other case for other keybindings, my function IsCurrentWindowNERDTree works everytime ; i binded nnoremap <C-V> :normal s<CR>, doesnt work either.

i dont understand what is wrong with <C-V>

any ideas? thanks

5
  • 1
    This is not an answer to your question but a friendly advice from someone who has been messing with NERDTree in the past: You are not doing yourself any favor trying to use NERDTree, bending it to your needs always creates frustration and hacky workarounds (also have a look here) also remapping <C-v> to paste text is a great way to cause issues in the future: <C-v> is super useful for visual block selection and not pasting with p leads to all kind of troubles (using different registers, pvsP,etc)
    – statox
    Jun 10 at 8:56
  • 1
    So once you debug your problem (which you should still do because that's a good learning opportunity) I real encourage you to ditch at least your <C-v> mapping and also to replace NERDTree with the built-in netrw, :ls, :b, `:find, etc and maybe a fuzzy finder if you really need one.
    – statox
    Jun 10 at 8:58
  • my entire question is debugging my problem. i understand that some people dont like nerdtree because they realised that is worthless, for me its useful. i already have fzf, i just like nerd tree standing alone there in the left. i solved the problem my selecting another keybinding, but i really wanted to use C-V and to find out what wrong with C-V, because there is something wrong, otherwise C-N wouldnt work also.
    – alexzander
    Jun 10 at 9:21
  • Of course that's why I said my comment wasn't answering your question and it was just a piece of unsolicited advice. I'm sure someone else will be more useful and will help you actually debugging that :)
    – statox
    Jun 10 at 9:24
  • 1
    honestly, i dont care anymore. its too much of a pain. i've found another key binding for that, and voilla, problem solved, but if someone smarter comes around and gives me the answer to why C-V has problems in vim, thanks.
    – alexzander
    Jun 10 at 9:28

Your Answer

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

Browse other questions tagged or ask your own question.