José Luis
José Luis

Reputation: 3933

Extend a vim command

How can I extend a command in vim?

I want to do it in two situations,

  1. After a :diffget or :diffput I always want to run a :diffupdate
  2. After a :NERDTreeToggle I want to run a <C-w>=

Upvotes: 2

Views: 667

Answers (3)

Peter Rincker
Peter Rincker

Reputation: 45107

I am unaware of any autocmd events that would be triggered for your scenarios. However a few custom mappings might be helpful.

You can change the default dp and do mappings to also do a :diffupdate

nnoremap dp dp:diffupdate<cr>
nnoremap do do:diffupdate<cr>

Note there are times where you cannot use dp and/or do and must use :diffput/:diffget. In these cases I would suggest you create a commands like so:

command! -nargs=? -range=1 -bar Diffput <line1>,<line2>diffput <args>|diffupdate
command! -nargs=? -range=1 -bar Diffget <line1>,<line2>diffget <args>|diffupdate

Or you can just map :diffupdate

nnoremap <f8> :diffupdate<cr>

NERDTree

nnoremap <leader>N :NERDTreeToggle<cr><c-w>=

Upvotes: 3

noahlz
noahlz

Reputation: 10311

Create your own custom function in VimScript in your .vimrc that wraps several commands.

Here's one I use to launch a Clojure Repl in a buffer using several plugins:

fun! LeinCMD()
    execute 'ConqueTerm lein repl'
    execute 'set syntax=clojure'
    execute 'normal! i'
endf
command! Repl call LeinCMD()

I then call this command with :Repl (note that your custom commands must always start with an uppercase letter).

Source: Automate running several vim commands and keystrokes

Upvotes: 0

lthms
lthms

Reputation: 519

Maybe you can have a look to the vim macro. It is probably suitable for what you want to do :).

Upvotes: 0

Related Questions