Question

I'm currently using this key mapping in my .vimrc file to simulate the Windows Cut keyboard shortcut. Cut, meaning copy and delete the selected text.

vnoremap <C-X> "+x

This key mapping is part of the mswin.vim script that ships with Vim, which i don't use, i only use a few key mapping from that file.

When i then select text from within Vim in insert mode and press CtrlX the text is copied and deleted but with the unwanted side effect of the cursor moving several characters back and performing Vim's normal behavior of a CtrlX press which is to decrement the number directly under the cursor!

For example, if i want to change the following code to cut the second occurrence of the word Renderer i start with this:

Renderer.setClearColorHex(0x7DB6D5, 1.0);
Renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);

and end up with this:

Renderer.setClearColorHex(0x7DB6D5, 1.-1);  // <--- oh dear!
.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);

Which causes more than a few bugs!

Is there anyway to avoid this unwanted behaviour with this keymap or is there another, safer way to Cut text in insert (SELECT) mode?

Was it helpful?

Solution

It was a conflict with the Snipmate plugin in file snipmate\after\plugin\snipMate.vim.

I commented out these lines and all is fine.

" snor <bs> b<bs>
" snor <right> <esc>a
" snor <left> <esc>bi
" snor ' b<bs>'
" snor ` b<bs>`
" snor % b<bs>%
" snor U b<bs>U
" snor ^ b<bs>^
" snor \ b<bs>\
" snor <c-x> b<bs><c-x>

OTHER TIPS

Do you actually use mswin.vim or not? AFAIK, a lot of things are done there in order to allow editing in INSERT mode and all that kind of monstrosity; if you only take one little snippet out there's no guarantee it will work correctly.

If you use MSWIN compatibility and this mapping is already in mswin.vim, why did you put it in your vimrc?

If you don't use MSWIN compatibility, there are many wrong things here:

  • "editing" text is not done in INSERT mode, you must go back to NORMAL mode and perform your editing there
  • when in NORMAL mode, d is the correct equivalent of Ctrl+X as it deletes what you want it to delete and puts it into the default register, ready to be pasted somewhere else.
  • you don't need to select a word to delete it, supposing you are on the R of Renderer, you should do dw to delete until the end of the current word
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top