:r ! find into tabnew?

17 views
Skip to first unread message

Robert Mark Bram

unread,
Dec 11, 2008, 9:08:05 AM12/11/08
to vim_use
Hi All,

I like tabs.. so I do this a lot:
:tabnew ./somefile.txt

But since I work with programming projects, the file I want to open is
usually not in the whatever dir I am currently editing from, so I have
done this a few times too in order to find my file:

:r ! find . -name *.css

Is there any way to combine the two? I.e. use the output of a find
command in a :tabnew? This would make it so easy to find and open
files at the same time. :)

Any help would be much appreciated!

Rob
:)

Robert Mark Bram

unread,
Dec 11, 2008, 9:15:42 AM12/11/08
to vim_use
:tabf .

Wow.. this is so cool.. and just *almost* enough, but I want the
search! :)

Rob
:)

Teemu Likonen

unread,
Dec 11, 2008, 9:37:42 AM12/11/08
to vim...@googlegroups.com
Robert Mark Bram (2008-12-11 06:08 -0800) wrote:

> :r ! find . -name *.css
>
> Is there any way to combine the two? I.e. use the output of a find
> command in a :tabnew? This would make it so easy to find and open
> files at the same time. :)

Perhaps this idea can be modified to match your needs:

http://vim.wikia.com/wiki/Display_shell_commands%27_output_on_Vim_window

In the function change the "botright new" line to "tabnew" and create
new Vim commands like this:

command! -nargs=+ Find call s:RunShellCommand('find '.<q-args>)

Then just ":Find -what -ever -arguments" will do.

Gary Johnson

unread,
Dec 11, 2008, 12:19:15 PM12/11/08
to vim...@googlegroups.com

:tabnew **/somefile.txt

See

:help wildcard
:help starstart-wildcard

Regards,
Gary

Robert Mark Bram

unread,
Dec 11, 2008, 11:29:24 PM12/11/08
to vim_use
Hi Teemu, thank you very much for the suggestion,
This is an awesome function. :)

Maybe I misunderstood what were getting at though. Here is what I put
in my .vimrc:

command! -complete=file -nargs=+ ShellTab call s:RunTabShellCommand(<q-
args>)
function! s:RunTabShellCommand(cmdline)
tabnew
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
call setline(1,a:cmdline)
call setline(2,substitute(a:cmdline,'.','=','g'))
execute 'silent $read !'.escape(a:cmdline,'%#')
setlocal nomodifiable
1
endfunction

command! -nargs=+ Find call s:RunTabShellCommand('find . -iregex '.<q-
args>)

But this opens a new [Scratch] buffer with the search results in a new
tab.

I want a new tab opened containing not the search results, but the
files I was searching for. :) I.e. I want to say
:Find myF.*.txt
and have myFile.txt opened in a new tab.

Rob
:)

Robert Mark Bram

unread,
Dec 12, 2008, 12:12:45 AM12/12/08
to vim_use
> I want a new tab opened containing not the search results, but the
> files I was searching for. :) I.e. I want to say
> :Find myF.*.txt
> and have myFile.txt opened in a new tab.

Well... I have it now.

The problem with what I asked for is that typically my searches come
up with more than one file.. so I want a way to search, choose and
open smoothly.

Teemu's idea gives me the easy "search", opening results in a new tab.

Then I found this page:
http://vim.wikia.com/wiki/Word_under_cursor_for_command

So all I have to do is press gf and it magically opens the file under
the cursor!

I love vim!

Rob
:)
Reply all
Reply to author
Forward
0 new messages