Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In the video at Watch how i work rails he first obtains the output of find . -type f and uses this list as a regular vim file to search. Ones he finds this file in the list, he can open it in vim. This looks really useful but he does not specify the alias to do it. Can someone give me the alias for the same?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

What's going on can be pieced together from the author's dotfiles. Warning! The whole thing is pretty convoluted (and smart).

  1. This is the vim- bash command:

    vim-() {
      vim -s <(printf '\eh')
    }
    

    It opens Vim and simulates a key sequence, <Esc>h.

  2. <Esc>h is mapped to execute a custom command, :FPScratchy which in turn calls an external script, ack_find.

    nmap <ESC>h :FPScratchy "ack_find"<CR>
    
  3. The purpose of that command is to create a "scratch window" containing the file list generated by the external command and do some remappings for navigation: <CR> in normal mode to open the file under the cursor, <CR> in visual mode to add the selected files to the local arglist and <Esc><CR> in normal mode to open the file under the cursor in a split window.

    function! FPScratchy(...)
      call call(function("Scratchy"), a:000)
      setlocal cursorline
    
      nmap <buffer> <CR> 0gf
      vmap <buffer> <CR> :Lines2arglocal<CR>
      nmap <buffer> <ESC><CR> 0<c-w>f<c-w>w
    endfunction
    command -nargs=* FPScratchy :call FPScratchy(<args>)
    
    function! Lines2arglocal() range
      let lines = map(range(a:firstline, a:lastline), 'getline(v:val)')
    
      execute "arglocal " . join(lines, " ")
    endfunction
    command -range Lines2arglocal <line1>,<line2>:call Lines2arglocal()
    
  4. The author changed his find-based method to a slightly more involved ack-based one a few years ago. Let's assume it was a simple

    $ find . -type f
    
share|improve this answer

There are several ways to do that. To get the output of that command into a Vim buffer, open Vim and execute

:r!find . type f

Another way to do that, using vim in a terminal, would be to execute the following at the shell prompt.

$ find . type f | vim -

I usually put the cursor over the desired file name and type

<C-W>f

where <C-W> means Ctrl-W. That will open the file in a new window, which avoids the problem of trying to open a new file in a modified buffer.

Another approach would be to first execute

:set nomodified

Then type

gf

That will open the new file in the buffer/window that contained the list of files.

Still another way would be to again put the cursor over the desired file name and execute

:e! <C-R>f<CR>

where <C-R> means Ctrl-R and <CR> means the Enter key. The <C-R>f combination will expand to the file name under the cursor.

See

:help :r!
:help CTRL-W_f
:help gf
:help 'modified'
:help c_CTRL-R_f
share|improve this answer
    
Even before that how do i get the file list in vim? –  MIkhail Aug 21 '13 at 15:23
    
Probably with :r!find . type f. See :help :r!. I'll update the answer. –  garyjohn Aug 21 '13 at 15:26
    
@MIkhail: If he starts from the command line and not from within an open Vim session, perhaps he is running find . -type f | vim -. This will grab STDIN and put it into the buffer. –  Daniel Andersson Aug 21 '13 at 15:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.