Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 1
    Are you familiar with key mapping (:h mapping)? You can trigger multiple commands with a keystroke or two. Commented Sep 24, 2021 at 20:50
  • ah, okay, so I suppose I can do something like this: :noremap <leader>d :diffoff!<cr> :diffthis<cr> <c-w>w :diffthis<cr> <c-w>W and then type <leader>d to diff the current window with the next window. I felt there would be an easier way, but that's not so hard, is it. Commented Sep 24, 2021 at 23:47
  • 1
    Yes but a few things. 1) It's nnoremap if it's a key map to be pressed in Normal mode. 2) You can separate commands with \| or <bar> instead of <cr>. The bar (aka pipe) character | is Vim's command separator. In mappings you must escape it, though. 3) To use Normal mode commands in a mapping mixed with Ex commands use :normal[!]. Alternatively, almost all Normal mode ctrl-w commands have Ex equivalents. See :h :wincmd. Commented Sep 25, 2021 at 0:39
  • 1
    And, yes, that may be a lot to absorb but once you're used to it you'll find that key mappings are the simplest, quickest form of automation. (Some would argue that macros are but those are ugly to edit/maintain. Best for one-offs.) Welcome to Vi&Vim SE, btw (10 months after the fact but your first post :) Commented Sep 25, 2021 at 0:46
  • Thanks @BLayer. This is useful. I am not comfortable with making mappings on the fly. So, taking your advice, perhaps something like this is more reasonable: :nnoremap <leader>d <Cmd>diffoff! \| diffthis \| wincmd w \| diffthis \| wincmd W<cr> to diff the current window with whatever's in the next window, as a reusable command I can save. Commented Sep 25, 2021 at 16:04