> 'abc' in FILE, from within vi.

* % means 'the current file' in vi commands so you can write
* | is the command separator
* grep has a -c flag to count occurrences

so you can write:

    :w|grep -c abc %

you can also write the content of the buffer to a pipe (my prefered
solution here):

    :w !grep -c

> Sadly, :E doesn't actually work in vim.  It says
> > E464: Ambiguous use of user-defined command

> I don't know what works in vim. vim prolly has a dozen
> chrome-electroplated ways to do the same thing, but I don't know them.

:h windows

also:

:h :new
:h :enew
:h gf
:h :bu
:h :ls
:h :bw

the following code isfrom my ~/.vimrc so i can:
 * navigate into buffers with <left> and <right> arrows
 * come back to the first buffer with <down>
 * have a fzf menu of the current buffers using <up>

set hidden
command! -nargs=0 BU redir! > ~/.v.json | silent echo json_encode(getbufinfo()) 
| redir END
  \| silent exec "!vim_BU ~/.v.json ~/.v"
  \|so ~/.v
  \|redraw!
nnoremap <up>     <esc>:BU<cr>
nnoremap <down>  :bfirst!<cr>
nnoremap <left>  :bnext!<cr>
nnoremap <right> :bprevious!<cr>

the code of vim_BU (i can probably get grid of perl and use jq instead):

vim_BU () {
        perl -MEnv -MJSON -w0 -nE'
                map +( printf "%3s %s%s %s\n"
                        , $$_{bufnr}
                        , ( $$_{hidden}       ? "h"       : "a" )
                        , ( $$_{changed}      ? "+"       : " " )
                        , ( length $$_{name}  ? $$_{name} : "NONAME" )
                ), @{ decode_json $_ }
        ' $1 | fzf | awk '{print "bu "$1}' > $2
}

regards
marc



Reply via email to