5 ms·
I didn't know about :r in combination with !. That's neat. I typically use :r for reading a file into the current buffer (instead of cp <file> <new>). Thanks fo
by blockloop 10y ago
I didn't know about :r in combination with !. That's neat. I typically use :r for reading a file into the current buffer (instead of cp <file> <new>). Thanks for sharing.
I don't find myself using ! commands when I know there are multiple commands that I need to run (like your last example). That's usually when I'll suspend and then use the command line.
Could you elaborate on "wreak havoc on your vim session?" I wasn't aware that suspending the process and bringing it back into the fg would harm anything.
- u801e 10y ago> I didn't know about :r in combination with ! You can even use :w in combination with !. For example :w !xclip to write the vim buffer contents to the clipboard. You could visually highlight part of the buffer and do the same thing for just the text you want.
- EvilTerran 10y agoThis is also useful for iterating on a throw-away script - something too long to type on one line in the shell, but not significant enough to be worth saving to a file. Put it together in an unnamed buffer, and ":w !" it to the relevant interpreter (eg ":w !perl") whenever you want to run it.
- deleted 10y ago[deleted]
- ves 10y agofor osx peeps: `:w !pbcopy`
- dotancohen 10y agoThough I understand that this is just an example of the power of `!r`, readers should know that VIM in fact can copy to the system clipboards natively. "*y "+y
- jacobmischka 10y agoOnly if it's compiled with clipboard support. I don't know about in other places, but in the default Arch package it's not. So this command is a perfect solution for me.
- Kubuxu 10y agoYou need to install `gvim` which provides `vim` with that feature.
- u801e 10y agoThat requires that vim be compiled with the xterm-clipboard feature enabled. On my Fedora 24 desktop, vim doesn't have it enabled, but gvim does (according to the output of the :version command). One advantage of the method you describe is that it can be limited to just part of a line. Piping output to xclip is limited to complete lines of text due to the nature of :w !.
- leni536 10y ago> That's usually when I'll suspend and then use the command line. That's when I run !bash, enter my list of commands, then exit.
- JdeBP 10y agoIf one wants something that isn't limited to one shell, and invokes the interactive shell that the user has chosen, there is of course :shell