How to combine windo/tabdo with a shortcutted command?

18 views
Skip to first unread message

tu...@posteo.de

unread,
Nov 27, 2020, 1:45:10 AM11/27/20
to vim...@googlegroups.com
Hi,

suppose I want to delete a line in each window or tab I currently
have in my vim...how can I do a

windo
or

tabdo

combined with 'dd' (and I am too lazy to lookup the command name
in the help for each shortcut I want to use this way... ;)

Is there a common way to this?

Cheers!
mcc




Tim Chase

unread,
Nov 27, 2020, 11:00:03 AM11/27/20
to tu...@posteo.de, vim...@googlegroups.com
On 2020-11-27 07:44, tu...@posteo.de wrote:
> suppose I want to delete a line in each window or tab I currently
> have in my vim...how can I do a
>
> windo
> or
>
> tabdo
>
> combined with 'dd' (and I am too lazy to lookup the command name
> in the help for each shortcut I want to use this way... ;)

Well for the "dd" case, that's the same as the ex ":d" command so you
can do

:windo d
:tabdo d

assuming that the cursor is positioned on the right line. If it's a
particular line like the first or last line in the file, you can
specify that:

:windo 1d
:windo $d

or if it's all lines matching a pattern,

:windo g/pattern/d

-tim


tu...@posteo.de

unread,
Nov 29, 2020, 1:10:30 PM11/29/20
to vim...@googlegroups.com
Hi Tim,

thanks for your reply!

Is there a more general way to acchieve this?

If I would had asked:
"I have a command, which is known by its shortcut only: How can I
execute this command for each tab or each window by using tabdo or
window respectively?"

Is there an answer even if the command itsself is not know first hand?

Cheers!
Meino
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201127095949.1f6b9036%40bigbox.attlocal.net.
>

Salman Halim

unread,
Nov 29, 2020, 1:15:53 PM11/29/20
to Vim Users
If you're duplicating keystrokes you might hit in normal mode, the command is :normal, so something like might work:

tabdo windo normal dd
tabdo windo normal Ihello<esc>

--

Salman

tu...@posteo.de

unread,
Nov 29, 2020, 1:19:32 PM11/29/20
to vim...@googlegroups.com
Hi Salman,

OH YES! :) Exactly what I have searched for! Thanks a lot!

Cheers!
Meino
> > https://groups.google.com/d/msgid/vim_use/20201129181017.huebjeeyumb7crfq%40solfire
> > .
> >
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEd7zKr0-k3PJ9hN9ftnvXC%3D11ug7M0ocZTOWv56YH6vYA%40mail.gmail.com.

Salman Halim

unread,
Nov 29, 2020, 2:19:32 PM11/29/20
to Vim Users
You're welcome. If you use windo and tabdo a lot, these versions might interest you. They work the same as the originals, but will restore your current window and tab after they're done. For example, if you execute ':windo set nu!', you'll end up in the last window you have open in the current tab; however, if you execute ':Windo set nu!', it will leave you in the same window as where you started.

You can use Tabdo and Windo just like the regular versions (I never use the built-in versions any more, to be honest):

function! TabDo( command )
  let currTab = tabpagenr()

  execute 'tabdo ' . a:command

  silent! execute currTab . 'tabnext'
endfunction
com! -nargs=+ -complete=command Tabdo call TabDo( <q-args> )

" Just like Tabdo except that it disables all autocommands for super fast processing.
function! TabDoFast( command )
  noautocmd call TabDo( a:command )
endfunction
com! -nargs=+ -complete=command Tabdofast noautocmd call TabDo(<q-args>)

function! WinDo(command)
  let currwin=winnr()

  execute 'windo ' . a:command

  silent! execute currwin . 'wincmd w'
endfunction
com! -nargs=+ -complete=command Windo call WinDo(<q-args>)

" Just like Windo except that it disables all autocommands for super fast processing.
function! WinDoFast( command )
  noautocmd call WinDo( a:command )
endfunction
com! -nargs=+ -complete=command Windofast noautocmd call WinDo(<q-args>)



--
 
Salman

I, too, shall something make and glory in the making.

tu...@posteo.de

unread,
Nov 29, 2020, 11:57:27 PM11/29/20
to vim...@googlegroups.com
Hi Salman,

WHOW! Thank you ***VERY MUCH!*** :) :) :) :) :)

Will insert those in my .vimrc!

Cheers!
Meino
> > https://groups.google.com/d/msgid/vim_use/20201129181918.k56bsfr6xhpyyg6u%40solfire
> > .
> >
>
>
> --
>
> Salman
>
> I, too, shall something make and glory in the making.
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEfw0HTjiOjycNt%2BeHDUuTXagg78iMu8vpS6-ExPaqRk4g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages