Search code examples
vimkeymapping

Mapping vim keys similar to Sublime's move line up/down


I use Sublime Text in Windows(feels natural in Windows even though there's gVim) and trying to use vim in Linux environment (vim feels natural in Linux even though there's Sublime for Linux).

I'm trying to map :m +1 and :m -2 which is similar to Sublime's Ctrl+Shift+Down and Ctrl+Shift+Up. My attempt at mapping it in my ~/.vimrc is as follows:-

nmap <C-S-Up> :m -2<CR>
nmap <C-S-Down> :m +1<CR>

But it doesn't seem to work. The following however do work but I wanted to get it close to Sublime's key mapping.

nmap <leader><S-Up> :m -2<CR>
nmap <leader>S-Down> :m +1<CR>

I also have to note that I'm using terminator as my console emulator which has Ctrl+Shift+Up and Ctrl+Shift+Down to resize the split window but I've already disabled those key binding and still vim doesn't like my Sublime way of mapping. :/

What am I doing wrong?


Solution

  • I think the problem is that vim doesn't understand <C-S-[whatever]> sequences. They're captured by your terminal emulator (which is able to understand them, e.g. <C-S-v> will usually paste text from the clipboard to the terminal).

    I don't know if there's something you can do about it in terminal vim; they should natively work in gVim.

    A more detailed explanation of this phenomenon is in this question on AskUbuntu.

    PS: I'm a fan of the vim-move plugin, which lets you move lines of text and blocks of text (highlighted in visual mode) up and down. It's very similar to what Sublime does, especially when it comes to blocks of text. It also reindents moved lines and blocks. I have mapped the functionality of this plugin to <A-j> and <A-k>, which feels very vimmy. Maybe you could map the same functionality on Sublime to the Alt keys so that you have to learn just one shortcut.