Is it possible to search mappings by the target command?
E.g: I would like to search which are the key sequences mapped to StripWhitespace.
I know you can search what is mapped to a key sequence using map {lhs} command. E.g:
map ,s
will show mappings to key sequences starting with ,s:
x ,s :StripWhitespace<CR>
n ,sb * :SortBlock<CR>
What I want to do is do the reverse of that.
You can use :filter sort of like using grep in the shell.
:filter /StripWhitespace/ map
:filter is new in Vim 8 so you have to have a relatively up-to-date Vim. You could also in theory use execute() however that is relatively new as well.
Older Vim version you will need to use :redir
:redir #"> | silent map | redir END | new | put | v/StripWhitespace/d_
For more help see:
:h :filter
:h execute()
:h :redir
:h :silent
:h :map
:h :new
:h :put
:h :v
:h :d
:h "_
Related
Currently I have the following user command (:h user-commands, :h :command)
:command -nargs=1 Browse !open <args>
The open command is a macOS cli utility that opens the browser.
When I invoke it with :Browse https://google.com/#my-fragment the # in the url will be expanded to the alternate (:h alternate-file , :h :_# , :h c_#), since there is no alternate it will error out with:
E194: No alternate file name to substitute for '#': !open 'https://google.com/#my-fragment'
In this case, and I want the <args> passed verbatim (no expansions), how can I prevent ALL expansions?
You should use fnameescape() or shellescape() (:h fnameescape(), :h shellescape()) in conjunction with :execute :
:command -nargs=1 Browse silent execute '!open' shellescape(<q-args>,1)
See (:h :silent, :h :execute, :h cmdline-special)
How to autoupdate search vimgrep results from quickfix window after file is autoudpated due to change?
I use :vim/pattern/% to search and put result in quickfix window.
You can always do <up> on the command line with a prefix of :vimgrep to make searching history easier. You may also want to check out q: and the use ?// to search for the command to re-execute.
Assuming the quickfix title is set correctly, you can use following the command:
:execute get(getqflist({'title':1}), 'title')
This however I am not certain this will work with all :grep/:make commands. You also need a newer Vim version to get the Quckfix list title (Vim 8+ I think).
If you find yourself doing this often you may want to bind a mapping or command.
command! -nargs=0 -bar QFRefresh execute get(getqflist({'title':1}), 'title')
Now how to add do this automatically? We can use FileChangedShellPost autocmd to run our QFRefresh command once a file change has been detected. Add the following to you vimrc file:
augroup QFRefresh
autocmd!
autocmd FileChangedShellPost * if get(b:, 'qfrefresh_auto', 0) | QFRefresh | endif
augroup END
command! -nargs=0 -bar QFAutoRefreshToggle let b:qfrefresh_auto = !get(b:, 'qfrefresh_auto', 0) | echo b:qfrefresh_auto ? 'Auto Refresh' : 'No Auto Refresh'
Now you can use :QFAutoRefreshToggle to toggle refreshing a file.
Note: As stated before QFRefresh uses the quickfix's title to get the quickfix command. If the title is not set correctly a refresh may not work correctly. Also I am not sure what guarantees Vim has on triggering FileChangedShellPost. You can force a check via :checktime command.
For more help see:
:h getqflist()
:h :execute
:h :get
:h q:
:h cmdwin
:h c_Up
:h FileChangedShellPost
:h :checktime
How can I show all lines in only open folds that match "foo"?
I tried this per "search only in folded text":
:folddoopen g/foo
but got this error: E147: Cannot do :global recursive
vim version: 7.3 (2010 Aug 15)
:folddoopen and :g cannot be used together in a meaningful way.
Instead, use :g with foldclosed():
:g/foo/if foldclosed('.') == -1 | # | endif
For more help see:
:help :g
:help /
:help :if
:help foldclosed()
:help :#
:help :foldopen
Is there a way to search inside the :digraph table in VIM ? the \is not working and my eyes are getting apart searching the glyphs I desire..
try :h digraph-table there you can do search with / or ?
You can capture the actual :digraph output in a scratch buffer via:
:redir #a | silent digraph | redir END | new +setl\ buftype=nofile\ bufhidden=wipe | put! a
Besides the answers given, you can try my unicode-plugin
You can then use the :Digraphs foobar to search for digraphs whose name match foobar
Combining Ingo’s accepted answer, Bill Odom’s answer on directing ex commands to a buffer, and Capturing ex command output from the Vim Tips Wiki produces the following snippet for your .vimrc.
function! TabDigraphs()
redir => message
silent digraphs
redir END
tabnew
setlocal buftype=nofile bufhidden=wipe
silent put =message
setlocal nomodified
endfunction
command! TabDigraphs call TabDigraphs()
Here is a map command.
nnoremap <F5> :w\|!R %<CR>
1.what is the meaning of \ here?
2. does | mean pipe ?
The | character separates two Ex commands, see :help :|. It's like ; in programming languages like C and Java. It has nothing to do with pipes; Vim hasn't that concept (which is typically found in shells).
It is escaped here so that the entire command sequence belongs to the mapping; i.e. it maps to :w|!R %<CR>. Without escaping, Vim would execute the following instead:
:nnoremap <F5> :w
:!R %<CR>
Note that you can also write <Bar> (cp. :help key-notation) instead of \|, and the former is more frequently used.