Vim icon indicating copy to clipboard operation
Vim copied to clipboard

Support tpope/vim-unimpaired

Open NGenetzky opened this issue 7 years ago • 9 comments

Is your feature request related to a problem? Please describe. I really miss using my [ and ] to navigate through lists in vim. Obviously not all those lists translate directly, but I find that many of them do.

Describe the solution you'd like Emulate the behavior of tpope/vim-unimpaired.

Describe alternatives you've considered I will begin implementing some of the functionality with keybindings.json.

NGenetzky avatar Dec 13 '18 22:12 NGenetzky

I miss following [/] mappings from vim-unimpaired

  • [<space>/ ]<space> insert empty line above/below
  • [e/ ]e moving lines around (I do not like the arrow based mappings from vscode)
  • [q/]q going through the quickfix list/build errors: next problem/previous problem

However, I also would like to have the toggle mappings (if applicable), e.g.

  • yon line numbers
  • yor relative line numbers (see https://stackoverflow.com/questions/43597322)
  • yow wrapping lines
  • yos spell checking

kiryph avatar Jan 14 '20 10:01 kiryph

A first try to define the unimpaired mappings [<space>, ]<space>, [e, ]e:

{
    "vim.normalModeKeyBindings": [
        {
            "before": [ "[", " " ],
            "after": [ "O", "<Esc>", "j", "0" ]
        },
        {
            "before": [ "]", " " ],
            "after": [ "o", "<Esc>", "k", "0" ]
        },
        {
            "before": [ "]", "e" ],
            "commands": [ "editor.action.moveLinesDownAction" ]
        },
        {
            "before": [ "[", "e" ],
            "commands": [ "editor.action.moveLinesUpAction" ]
        }
    ],
    "vim.visualModeKeyBindings": [
        {
            "before": [ "]", "e" ],
            "commands": [ "editor.action.moveLinesDownAction" ]
        },
        {
            "before": [ "[", "e" ],
            "commands": [ "editor.action.moveLinesUpAction" ]
        }
    ]
}

Dot-repeat does not work for [e and ]e.

kiryph avatar Jan 06 '21 09:01 kiryph

I recently made the keybindings for the l ]q and [q (at lwast in context of the diff view). I would be interested in helping identify or verify others.

On Wed, Jan 6, 2021, 03:32 kiryph [email protected] wrote:

A first try to define the unimpaired mappings [, ], [e, ]e:

{ "vim.normalModeKeyBindings": [ { "before": [ "[", " " ], "after": [ "O", "<Esc>", "j", "0" ] }, { "before": [ "]", " " ], "after": [ "o", "<Esc>", "k", "0" ] }, { "before": [ "]", "e" ], "commands": [ "editor.action.moveLinesDownAction" ] }, { "before": [ "[", "e" ], "commands": [ "editor.action.moveLinesUpAction" ] } ], "vim.visualModeKeyBindings": [ { "before": [ "]", "e" ], "commands": [ "editor.action.moveLinesDownAction" ] }, { "before": [ "[", "e" ], "commands": [ "editor.action.moveLinesUpAction" ] } ] }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/VSCodeVim/Vim/issues/3263#issuecomment-755189559, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADBE2V22AU6F5YYXBKIXO2DSYQU2TANCNFSM4GKKHBEA .

NGenetzky avatar Jan 06 '21 09:01 NGenetzky

@NGenetzky could you share your mappings?

I'm looking for:

  • setting toggles (yoc, yon, yoh, ect)
  • next previous problem ]l [l

Figured I would share this since it's related but actually part of vim-gitgutter

Move to the next/previous version control chunk in a file

        // vim-gitgutter
        {
            "before": [ "]", "c" ],
            "commands": [ "editor.action.dirtydiff.next" ]
        },
        {
            "before": [ "[", "c" ],
            "commands": [ "editor.action.dirtydiff.previous" ]
        },
        {
            "before": [ "]", "c" ],
            "commands": [ "workbench.action.compareEditor.nextChange" ]
        },
        {
            "before": [ "[", "c" ],
            "commands": [ "workbench.action.compareEditor.previousChange" ]
        },

IanEdington avatar Jan 10 '21 02:01 IanEdington

A few more for you here: (the last few are not standard in vim-unimpaired)

{ "before": [ "[", "b" ], "commands": [ "workbench.action.previousEditor" ] },
{ "before": [ "]", "b" ], "commands": [ "workbench.action.nextEditor" ] },
{ "before": [ "[", "f" ], "commands": [ "workbench.view.explorer", "list.focusUp", "explorer.openAndPassFocus" ] },
{ "before": [ "]", "f" ], "commands": [ "workbench.view.explorer", "list.focusDown", "explorer.openAndPassFocus" ] },
{ "before": [ "[", "q" ], "commands": [ "search.action.focusPreviousSearchResult" ], "when": "hasSearchResult" },
{ "before": [ "]", "q" ], "commands": [ "search.action.focusNextSearchResult" ], "when": "hasSearchResult" },
{ "before": [ "[", "r" ], "commands": [ "references-view.prev" ], "when": "reference-list.hasResult" },
{ "before": [ "]", "r" ], "commands": [ "references-view.next" ], "when": "reference-list.hasResult" },
{ "before": [ "[", "l" ], "commands": [ "editor.action.marker.prevInFiles" ], "when": "editorTextFocus" },
{ "before": [ "]", "l" ], "commands": [ "editor.action.marker.nextInFiles" ], "when": "editorTextFocus" },
{ "before": [ "[", "g" ], "commands": [ "workbench.action.editor.previousChange" ], "when": "editorTextFocus" },
{ "before": [ "]", "g" ], "commands": [ "workbench.action.editor.nextChange" ], "when": "editorTextFocus" },
{ "before": [ "[", "w" ], "commands": [ "workbench.action.focusPreviousGroup" ] },
{ "before": [ "]", "w" ], "commands": [ "workbench.action.focusNextGroup" ] },

From my settings.json file.

joeytwiddle avatar Mar 18 '21 04:03 joeytwiddle

This is what I use for diff

{ "before": ["y", "o", "d"], "commands": ["git.openChange"] }

I'm not sure how to toggle it. Return to the current state of the file and close diff

ultrox avatar Apr 09 '22 11:04 ultrox

Some more, looks like we are getting close!

  {
    // like `:set wrap!`
    "before": ["y", "o", "w"],
    "commands": ["editor.action.toggleWordWrap"],
  },
  {
    // like `:set listchars!`
    "before": ["y", "o", "l"],
    "commands": ["editor.action.toggleRenderWhitespace"],
  },
  {
    // If you set a "workbench.preferredDarkColorTheme", and a
    // "workbench.preferredLightColorTheme", `yob` will toggle between them,
    // otherwise it toggles between VSCode's Default Light+/Dark+ themes
    "before": ["y", "o", "b"],
    "commands": ["workbench.action.toggleLightDarkThemes"],
  },
  {
    // cSpell has different options for workspace vs global here
    "before": ["y", "o", "s"],
    "commands": ["cSpell.toggleEnableSpellChecker"],
  },

craigmac avatar Jan 31 '23 20:01 craigmac

@NGenetzky could you share your mappings?

I'm looking for:

* setting toggles (yoc, yon, yoh, ect)

* next previous problem `]l` `[l`

Figured I would share this since it's related but actually part of vim-gitgutter

Move to the next/previous version control chunk in a file

        // vim-gitgutter
        {
            "before": [ "]", "c" ],
            "commands": [ "editor.action.dirtydiff.next" ]
        },
        {
            "before": [ "[", "c" ],
            "commands": [ "editor.action.dirtydiff.previous" ]
        },
        {
            "before": [ "]", "c" ],
            "commands": [ "workbench.action.compareEditor.nextChange" ]
        },
        {
            "before": [ "[", "c" ],
            "commands": [ "workbench.action.compareEditor.previousChange" ]
        },

I noticed that if i have a buffer open with split screen looking at the compareEditor then the [ c binding causes a jump. Maybe a when condition is needed.

w-tr avatar Oct 26 '23 14:10 w-tr

A first try to define the unimpaired mappings [<space>, ]<space>, [e, ]e: [...] { "before": [ "[", " " ], "after": [ "O", "<Esc>", "j", "0" ] }, { "before": [ "]", " " ], "after": [ "o", "<Esc>", "k", "0" ] },

@kiryph I used ^ instead of 0 as vim goes to the first character of the line instead of the beginning of the line. Weirdly, neovim stays in the same position, but that behavior is also doable:

         {
             "before": [ "[", " " ],
             "after": ["m", "z", "O", "<Esc>", "`", "z"]
         },
         {
             "before": [ "]", " " ],
             "after": ["m", "z", "o", "<Esc>", "`", "z"]
         },

m saves the cursor position, and the backtick goes back to it (single quote only goes back to the cursor's line, not to its exact position)

EDIT: I am having issues with [ , I think somehow mz doesn't update the position of the mark after adding the line above with O (even though that works when testing manually), so I had to use the much weirder

"after": ["m", "z", "y", "y", "p", "`", "z", "j", "m", "z", "k", "0", "d", "$", "`", "z"]

in a nut shell, mark position, duplicate line below, go back to exact position, go one line down, mark new position, go one line up, delete whole line, go back to position. Bit of an over-engineered bummer, but I couldn't make it work any other way while keeping the position.

arty-hlr avatar Oct 07 '25 22:10 arty-hlr