≡

wincent.dev

  • Products
  • Blog
  • Wiki
  • Issues
You are viewing an historical archive of past issues. Please report new issues to the appropriate project issue tracker on GitHub.
Home » Issues » Feature request #1771

Feature request #1771: Ability to "seed" search string when calling up Command-T

Kind feature request
Product Command-T
When 2011-01-29T20:01:19Z
Status open
Reporter Greg Hurrell
Tags no tags

Description

From a user email:

I have a shell alias that launches vim in a particular project, setting the tags file, working directory, and other things from the command line. I'm trying to get it so I can pass in a Command-T search string and have the search box be prefilled with what I specified on the command line at launch. So for example, I might do viproj admin.php and I would see a list of all of the admin.php files.

I've been poking at this for a little while, attempting things like this:

$VI -c "set tags=~/src/$BRANCH/tags" -c "CommandT" -c "sleep 1" -c "normal! $CMDTSEARCH"
$VI -c "set tags=~/src/$BRANCH/tags" -c "CommandT" -c "sleep 1" -c "call CommandTHandleKey('$CMDTSEARCH')"

without luck.

I'm still poking around and peaking inside the CommandT controller.rb file to see if there's another way to do what I want, but in the meantime I thought I'd just ask and see if you could provide any suggestions.

With this follow-up:

FYI I found a solution that works without hacking inside CommandT (I also started on a solution from within CommandT, which I'll detail below in case you want to run with it).

Add a function to .vimrc like so:

function! CommandTSeed(word)
   execute "CommandT"
   let chars = split(a:word,'\zs')
   for char in chars
     call CommandTHandleKey(char2nr(char))
   endfor
endfunction

And then call vim like so to get all command-t results for search string admin:

vim -c "call CommandTSeed('admin')"

Works like a charm.

That said, here's what I started doing to make things work from within Command T. Perhaps you will see fit to add to a future version:

In prompt.rb add this function:

def search searchstr
  @abbrev = searchstr
  cursor_end
  redraw
end

In controller.rb, add this function:

def search
  @prompt.search ::VIM::evaluate('a:search')
end

In command-t.vim add this function:

function s:CommandTSearch(search, arg)
 if has('ruby')
   ruby $command_t.show
   ruby $command_t.search
 else
   call s:CommandTRubyWarning()
 endif
endfunction

And then turn that into a command (the command was failing for me so sorry this part isn't working):

command -nargs=+ CommandTSearch call <SID>CommandTSearch(<f-args>)

I didn't get it to work before noticing that the handle_key function, which I tried to manipulate earlier, took an int and not a char. So I went back and my external function worked so I didn't get the Command-T changes to 100%. But I hope this helps and hope you add the functionality to make it easier for others to do this in the future.

Comments

    Add a comment

    Comments are now closed for this issue.

    • contact
    • legal

    Menu

    • Blog
    • Wiki
    • Issues
    • Snippets