Is there a way to search inside the digraphs in Vim - vim

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()

Related

ctags unable to find variables that contain hyphen

I'm a big user of Vim's ctags ctrl-] shortcut. I recently made a tag file in which the primary language is Make. When I try to ctrl-] with my cursor over a variable with a hyphen (ex. dl-routines), I get an error. If my cursor is over 'dl' within the 'dl-routines' variable I get the error
tag not found: dl
If my cursor is over 'routines' within the 'dl-routines' variable I get the error
tag not found: routines
I'm aware of Vim's
:ta tagname
However I'd like to use ctrl-] as it gives me less room for error.
In this case it's probably worth altering 'iskeyword' option to include dash. It may have many other effects, but they all should be quite useful. The only trick is to make these changes locally:
autocmd FileType make setlocal iskeyword+=45
Setting 'iskeyword' option locally is probably the simplest solution. As an addendum to #Matt's answer, if you want to keep your option clean and add 45 only when you press <C-]>, you could use this trick function.
function! CWordWithKey(key) abort
let s:saved_iskeyword = &iskeyword
let s:saved_updatetime = &updatetime
if &updatetime > 200 | let &updatetime = 200 | endif
augroup CWordWithKeyAuGroup
autocmd CursorHold,CursorHoldI <buffer>
\ let &updatetime = s:saved_updatetime |
\ let &iskeyword = s:saved_iskeyword |
\ autocmd! CWordWithKeyAuGroup
augroup END
execute 'set iskeyword+='.a:key
return expand('<cword>')
endfunction
which adds the parameter key to iskeyword and sets a self-destructing autocmd to restore your older iskeyword after 200 ms.
Than remap <C-]> in ftplugin/make.vim or with autocmd FileType make ... as the previous answer.
nnoremap <buffer> <silent> <C-]> :execute 'tag '.CWordWithKey(45)<CR>

How to autoupdate vimgrep search result in quickfix window?

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

Is there a way to do reverse search of vim mappings?

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 "_

Can listings in the awful 'more' be displayed, instead, in a vim window?

In vim, neovim, when getting listings of mappings (eg :map), or when looking at self-defined or system defined variables (:let or :set), the results are display in a 'more' pager window.
There is probably some dim-recesses-of-time reason why (in vim) 'more' is used to display data - not vim. But what I, and I think millions of others, would like to know is this: How to make it stop!(?)
If, because 'reasons', vim just cannot display this data - in vim - then how can some solution from the third millennium, such as 'less', be used instead of the awful 'more'?
You can redir Vim output, it's a bad system but it works.
redir #a
silent map
redir end
then open a new buffer and paste the contents of a in insert mode:
ctrl-r a
You could create a custom command for this too to make map a dynamic string input.
To extend on Andy Ray's answer, here is a custom command that will redirect the output of a Vim or external command into a scratch buffer:
function! Redir(cmd)
for win in range(1, winnr('$'))
if getwinvar(win, 'scratch')
execute win . 'windo close'
endif
endfor
if a:cmd =~ '^!'
execute "let output = system('" . substitute(a:cmd, '^!', '', '') . "')"
else
redir => output
execute a:cmd
redir END
endif
vnew
let w:scratch = 1
setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile
call setline(1, split(output, "\n"))
endfunction
command! -nargs=1 Redir silent call Redir(<f-args>)
Usage:
:Redir hi " show the full output of command ':hi' in a scratch window
:Redir !ls -al " show the full output of command ':!ls -al' in a scratch window
:Redir in action:
What it does:
Close any scratch window created by a previous execution of :Redir.
Grab the output the desired command.
Open a new buffer in a vertical window.
Make the new buffer a scratch buffer.
Insert the output of the desired command.

How do I open the quickfix window instead of displaying grep results?

I am searching through a large codebase and find vimgrep unusably slow, so I'm using :grep from within vim, which displays a list of files, then says Press ENTER or type command to continue.
After I press Enter I can then type :copen to get to the list of results. But I'm wondering if I could automate this process? Adding the -q flag to grep seems to have the effect of causing grep to do nothing and then copen to be blank, which, unless I'm doing something wrong here, isn't really desirable.
I am using vim 7.4
You could define such a command :
command! -bar -nargs=1 Grep silent grep <q-args> | redraw! | cw
This will allow you to call it like Grep pattern, and :cw which opens the quickfix list only if it isn't empty.
Use an autocommand. Here is the one suggested by Tim Pope for :Ggrep. It will work for your case as well:
autocmd QuickFixCmdPost *grep* cwindow
For more information see:
:h :au
:h QuickFixCmdPost
:h :cwindow

Resources