Code Monkey home page Code Monkey logo

vim-move's Introduction

move

It's annoying to delete and paste parts of a text just to move it up/down or left/right a bit. There is the :m[ove] command but it is quite awkward to use by todays standards. vim-move is a Vim plugin that moves lines and selections in a more visual manner. Out of the box, the following keys are mapped in visual and normal mode:

<A-k>   Move current line/selection up
<A-j>   Move current line/selection down
<A-h>   Move current character/selection left
<A-l>   Move current character/selection right

The mappings can be prefixed with a count, e.g. 5<A-k> will move the selection up by 5 lines.

Features:

  • vertical motions
  • horizontal motions
  • automatic indentation
  • undo multiple moves with single :undo

See this short demo for a first impression:

vim-vertical-move demo

vim-horizontal-move_demo

Installation

vim-move is compatible with all major plugin managers. To install it using Vundle, add

Bundle 'matze/vim-move'

to your .vimrc.

To install it using vim-plug, add

Plug 'matze/vim-move'

to your .vimrc.

Customization

Use g:move_key_modifier to set a custom modifier for key bindings in normal mode. For example,

let g:move_key_modifier = 'C'

which will create the following key bindings:

<C-k>   Move current line/selections up
<C-j>   Move current line/selections down

Use g:move_key_modifier_visualmode to set a custom modifier for key bindings in visual mode. For example,

let g:move_key_modifier_visualmode = 'S'

which will create the following key bindings:

<S-k>   Move currently selected block up
<S-j>   Move currently selected block down

And so on...

NOTE

Both g:move_key_modifier and g:move_key_modifier_visualmode default to 'A' for backwards compatibility with previous versions of vim-move.

If the default mappings do not work, see the move_normal_option option in the help doc.

License

This plugin is licensed under MIT license.

vim-move's People

Contributors

booperlv avatar doronbehar avatar dzfrias avatar fpereira1 avatar hugomg avatar imhosseinzadeh avatar jedrzejboczar avatar matze avatar mmikeww avatar nkakouros avatar omcsesz avatar rr- avatar saulaxel avatar tecfu avatar vitalk avatar ypid avatar yukunlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-move's Issues

doesnt works in vi??

sorry, I'm a bit newbie with vim and I've notice than works with gvim but not when I try with vi..is it a limitation or I did a mistake??..thanks!...

Use S as move_key_modifier

I would like to use Shift + k and Shift + j to move, but this doesn't solve my problem and doesn't work.

let g:move_key_modifier = 'S' 
let g:move_key_modifier_visualmode = 'S'

I'm on fedora 38 with vim-enhanced.x86_64.

Out-of-box keymaps for moving are not working

Hello!

After installing the plugin, I noticed that the Alt-j, Alt-k, Alt-h, Alt-l combinations are not working at all neither in Insert mode, nor in Normal mode. Can you please support?

Crashing and CPU hog

This plugin repeatedly crashes if you hold down j or k to move a line up or down continuously.

The crash of vim results in 59% of CPU time being taken up; which consumes 100% of an entire core. The only way to resolve the crash is by SIGKILLING the process.

Better default mappings for macOS: use arrow keys

After my comments a couple of weeks ago on #71 (comment), I realized that not everything was working. So I revisited the configuration. My conclusion is that the default bindings for vim-move are not ideal.

Here are the problems as I see them:

  • I don't want to use C as the modifier because <C-l> is useful for redrawing the screen (and in neovim, also clearing any search highlighting).
  • I don't want to use S as the modifier because I'd like to figure out mappings that would work the same with vim and with JetBrains and VS code and the Shift key is often used in GUI apps to mean "extend the selection"
  • So that leaves the A modifier which on macOS is the Option key.
  • But if we select A, there are problems with using the h, j, k, l keys. In the terminal (at least iTerm), the recommended setting is to make the left Option key map to <Esc>+. The problem comes when you're in visual mode in the terminal and you hit Esc to exit out of Visual mode and then hit one of the above motion keys, such as h. What happens is that because of the vim-move mappings, this would be interpreted as a vim-move operation. One workaround is to hit Esc and wait until vim times out—but who wants to wait around? So the solution is to map to arrow keys instead of h and friends. Bonus: JetBrains and VS Code IDEs already use the arrow keys for moving line/statements, so the mappings will be similar or even the same (default VS code mappings for moving a line is indeed Option + arrow keys).

This is what I've figured out works very well for vim and neovim in iTerm2 terminal and in MacVim and VimR:

let g:move_map_keys = 0

if has("gui_running")
  nmap <A-Down> <Plug>MoveLineDown
  nmap <A-Up> <Plug>MoveLineUp
  nmap <A-Left> <Plug>MoveCharLeft
  nmap <A-Right> <Plug>MoveCharRight
  vmap <A-Down> <Plug>MoveBlockDown
  vmap <A-Up> <Plug>MoveBlockUp
  vmap <A-Left> <Plug>MoveBlockLeft
  vmap <A-Right> <Plug>MoveBlockRight
else
  nmap <Esc><Down> <Plug>MoveLineDown
  nmap <Esc><Up> <Plug>MoveLineUp
  nmap <Esc><Left> <Plug>MoveCharLeft
  nmap <Esc><Right> <Plug>MoveCharRight

  " WARNING: if instead of using h,j,k,l, you tend to use arrow keys for motion
  " in Normal mode, then the mappings below may interfere when you try to exit
  " out of Visual mode with <Esc> and immediately hit an arrow key. In that
  " case, you might want to use the `C` modifier instead as here:
  "vmap <C-Down> <Plug>MoveBlockDown
  "vmap <C-Up> <Plug>MoveBlockUp
  "vmap <C-Left> <Plug>MoveBlockLeft
  "vmap <C-Right> <Plug>MoveBlockRight
  vmap <Esc><Down> <Plug>MoveBlockDown
  vmap <Esc><Up> <Plug>MoveBlockUp
  vmap <Esc><Left> <Plug>MoveBlockLeft
  vmap <Esc><Right> <Plug>MoveBlockRight
endif

It took quite some time to figure this out. So I think that it would help mac users if either these were the defaults or there was a section in the README that listed all of these.

Undoing a move opens folds

Sometimes if we move over a folded section and then undo it then it opens the folded section. In the following example, if we move the "aaa" down by one and then undo it opens the fold between {{{ and }}}.

# vim:foldenable:foldmethod=marker

aaa
# {{{
bbb
# }}}
ccc

This might have to do with the cursor position. When the fold gets opened the cursor ends up in the line with the {{{.

Moving block including indents

If I have something like below and try to move lines 2-3 together, they will not maintain the indents -- 3 will be moved to the level of 2. The level difference should be maintained.

1
   2
      3
4

When I'm working with indented notes maintaining level differences is essential.

How to restore the position in the line after moving?

Currently when you are in the middle of the line, and using vim-move to move the current line, then the point of the cursor will be placed at the beginning of the line.

This is annoying when the word of the point before moving is important, and when I have multiple such lines(not in a block) to move, then I have to keep moving back to the middle of the line(the old point) manually.

Is it possible to make the point untouched when moving line(s) or restore the point in the line after moving line(s)?

Allow disabling for certain filetypes

This plugin is active when viewing help. If one types a mapping to move a line up or down then an error is shown as the help file is locked (modifiable off). I couldn't find a clean way to disable this plugin for help files.

Intendation of moving blocks get lost

Hi Matthias,

I'm working with your plugin on a daily basis and I lost the intendation when I moved a ruby block around in some markdown file.

Before moving code around:

{% highlight ruby %}

{% endhighlight %}

SimpleCov.start do
  add_group "Models", "app/models"
  add_group "Controllers", "app/controllers"
  add_group "Helpers", "app/helpers"
  add_group "Mailers", "app/mailers"
end

Now after moving around the SimpleCov.start block into the highlight block, I get the following result:

{% highlight ruby %}

SimpleCov.start do
add_group "Models", "app/models"
add_group "Controllers", "app/controllers"
add_group "Helpers", "app/helpers"
add_group "Mailers", "app/mailers"
end 

{% endhighlight %}

Can you reproduce this behavior or has it something to do with my with my vim setup?

Best regards from Berlin,

Matthias

Moving lines closes folds

Moving lines around while using folds results in folds getting closed. See #3 (comment) .

I'd really like to be able to have my folds stay the way they are and move some lines around where I am currently coding. I really like this plugin but having to open all folds to move some lines and then closing them again (loosing the current state of folds) is a bit tiresome. :-(

Or maybe there is just a setting I am missing?

Can't move in normal mode

When setting this plugin, I can move line in normal mode in vimrc file, but when open another file like sh or ruby file, I only can move in visual mode, normal mode don't work.
My vimrc config:

let g:move_map_keys = 0
nmap <C-k> <Plug>MoveLineUp
nmap <C-j> <Plug>MoveLineDown
vmap <C-k> <Plug>MoveBlockUp
vmap <C-j> <Plug>MoveBlockDown

Ubuntu 15.04, vim 7.4 patch 699 custom build

Custom key mapping not working properly in neovim

I have several .lua files in the config directory. I remap keyboard shortcuts with let g:move_map_keys = 1 on

local keymap = vim.api.nvim_set_keymap
kemayp("", "C-h", "<Plug>MoveCharLeft", { noremap = true, silent = true })
keymap("", "C-l", "<Plug>MoveCharRight", { noremap = true, silent = true })

and it works only after entering the command :so %.

Also there are my keyboard shortcuts:

keymap("n", "<A-l>", ">>", { noremap = true, silent = true })
keymap("v", "<A-l>", ">gv", { noremap = true, silent = true })
keymap("n", "<A-h>", "<<", { noremap = true, silent = true })
keymap("v", "<A-h>", "<gv", { noremap = true, silent = true })

How can I map J K to move block down and up?

I have some key mappings but it didn't work like I expected.

let g:move_map_keys = 0
let g:move_undo_join = 0  
xnoremap J <Plug>MoveBlockDown                                                       
xnoremap K <Plug>MoveBlockUp
xnoremap H <Plug>MoveBlockLeft
xnoremap L <Plug>MoveBlockRight

I don't want to use default or . Thanks in advance

Noremap version of mappings

When I use the normal nmap or vmap, the plugin works fine, but if I try to use nnoremap or vnoremap, it doesn't work at all. Why is this? I think it's better to always use the noremap versions. Can the plugin be updated to support this?

The wrong installation method in vim-plug

In the installation section mentioned to install the plugin in vim-plug add
Plugin 'matze/vim-move'

but this causes the following error

Not an editor command: Plugin 'matze/vim-move'

becuase vim-plug used Plug as keyword not Plugin.

Use something other than h,j,k,l for movement

I've looking into using something other than the default movement keys. I didn't know if this was already on your radar or not. I'd love to use my arrow keys as I'd rather use CTRL+J/CTRL+K for more used purposes.

<A-j> and <A-k> do not work

I'm unable to get the plugin to work with the default key bindings.

I've tried both left and right Alt key.

Here is the content of my .vimrc

set nocompatible               " be iMproved
filetype off                    " required!

set encoding=utf-8

filetype plugin on

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
Bundle 'gmarik/vundle'
Bundle 'matze/vim-move'
filetype plugin indent on     " required!

When I set let g:move_key_modifier = 'C' it works. I've tried with let g:move_key_modifier = 'A' to no avail

any ideas why it's not working with the default alt key binding ?

Can't move to the right when it finds a tilded character

I'm not sure if this is possible to fix, but I can't move a char or a selection to the right side if there's a tilded character, for example:

this line has a tilded character just hére
                                      |

So the movement stops where there's the | symbol.

I checked the functions getpos() and getcurpos() in Vim (Vim-native functions) and of course this is the problem: the third coordinate jumps two numbers after the tilded character.

From [0, 1, 40, 0, 40] to [0, 1, 42, 0, 41], when it should be [0, 1, 41, 0, 41].

If you think it's a Vim issue, it's ok, but I think it's expected on Vim, so it should require a specific solution in plugin-territory.

The issue does not happen going to the left side.

Options to disable all default mappings?

I'd like to only enable some mappings and disable others - is it possible to have a global "disable default mappings" option so that we can safely map to anything we'd like afterwards?

Undo doesn't undo the whole move

I'm not sure if it's possible but it would be nice if after moving a block around, hitting 'u' just once would cancel the whole move and put it back where it was initially, instead of undoing only the latest single line move.

Installing with pathogen

Hi,

I did:

git clone https://github.com/matze/vim-move.git ~/.vim/bundle/vim-move

I have other plugins working on ~/.vim/bundle.

But I can't move lines with alt+j or alt+k. How could I troubleshoot?

Instructions unclear.

How do I use this plugin?

I was trying to remap it to using 'Alt' as a key leader to find out whether another key binding conflicts.
I think I don't get how to use this plugin.

What I was trying out is (given let g:move_key_modifier='Alt'):

  • Be in normal mode
  • Switch to visual mode using v or ctrl+v shift+v (v-line mode)
  • Select a few lines of text
  • Press alt+j or alt+k.
  • Visual mode ends, nothing happens!?

Using Shift-A as a leader directly exists visual mode in my vimrc, no idea what to change to make this work, as Alt + j/k/whatever is pretty much unbound.

What is the workflow of this plugin to use it? I guess I misinterpreted how to use this correctly.

Move opens fold

I have several folds in my vimrc (with {{{ and }}}) to keep an overview about the stuff in there. When I use vim move in the upper part of the document it opens the last fold. After it is opened the fold is no longer recognized as fold so it can not be closed anymore. I am using vim 7.4

[Feature Request] Add visual selection left/right movement

I'm wondering if it's possible to add functionality that allows movement of a visual selection (non-full-line) left and right within a line, shifting the characters outside the selection left and right as the selection is moved left or right within the line...

Consider adding the following (new/configurable) key bindings:

<A-h>   Move visual selection left
<A-l>   Move visual selection right

For ex, the following line of html:

<div id="example" class=""></div>

I'd like to move the id attribute value to the class value (for whatever reason), so I visually select example:

<div id="example" class=""></div>

and I would like to shift example over to the right inside of class, so I press 9<A-l> to move class over 9 columns to the right:

<div id="" class="example"></div>

or move it over by pressing <A-l> repeatedly until I've shifted it over column by column:

<div id="example" class=""></div>
<div id="" exampleclass=""></div>
<div id="" cexamplelass=""></div>
<div id="" clexampleass=""></div>
<div id="" claexampless=""></div>
<div id="" clasexamples=""></div>
<div id="" classexample=""></div>
<div id="" class=example""></div>
<div id="" class="example"></div>

add option to not map line up/down

I really like having these mappings that map <c-j> and <c-k> for ale in normal mode to navigate errors. For now I've deleted those mappings from this plugin. I thought it would be nice to have those mappings be configurable to be disabled. As it's not too much effort to visually select the current line.

Meta not working as move_key_modifier

Hi,

I'm having problems with the default move_key_modifier on both Mac (iTerm/built-in Terminal) and Linux Mint. With

let g:move_key_modifier = 'C'

everything works as expected, but I've reserved the combinations C-jk for other tasks. Manually replacing s:MoveKey('j') in

execute 'nmap' s:MoveKey('j') '<Plug>MoveLineDown'

with the symbol from (CTRL+V) M-j also works, but it is a clumsy solution and requires different symbols on Mac and Linux.

The output of :nmap shows that the shortcut for MoveLineDown is a weird letter, but it doesn't help if I add settings for UTF-8 in a different place in my vimrc.

Do you have an idea on what could be wrong?

Thanks,

Robert

Moving by multiple lines does not work anymore

When I try moving a line multiple times at once with 5<A-k>, it only moves it by one line. I tested old versions of the plugin and I think that the commit that broke this functionality was 0d4737c. However, I am not 100% sure.

I use Neovim 0.4.3 but I think the issue also happens in regular Vim.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.