Exploit popups as much as you can!
* Vim-poptools *
Poptools aims to scale your productivity by conveniently using popups for a multitude of tasks, from finding files and directories, to setting your favorite colorscheme. Once a list of results is slammed into a popup menu, you can filter it in an fuzzy or exact fashion.
Poptools is more essential compared to similar plugins such as fzf, fuzzyy or scope and differently from them, external programs are called synchronously, although things may change in the future. :)
Nevertheless, I personally like the interface and how it displays all the results at once. Additionally, I find the opportunity of saving the last search very handy. The configuration is also fairly straightforward.
The following is what you can search and show in popups. The commands are self-explanatory:
:PoptoolsFindFile
:PoptoolsFindFileInPath # Takes into account the setting of :h 'path'.
:PoptoolsFindDir # Search from the current directory downwards
:PoptoolsBuffers
:PoptoolsRecentFiles
:PoptoolsCmdHistory
:PoptoolsKill # When something goes wrong, you can clear all the Poptools popups
:PoptoolsColorscheme # The displayed colors depends on the value of :h 'background'
:PoptoolsGrepInBuffer # Find pattern in the current buffer
:PoptoolsGrep # External grep. Grep command is displayed.
:PoptoolsVimgrep # Vimgrep, show results in the quickfix-list instead of a popup.
:PoptoolsLastSearch # Show the last search results
... and if you are curious, the following is how I mapped them in my .vimrc
:
nnoremap <c-p> <cmd>PoptoolsFindFile<cr><cr>
nnoremap <c-p>l <cmd>PoptoolsLastSearch<cr>
nnoremap <c-tab> <cmd>PoptoolsBuffers<cr>
nnoremap <c-p>o <cmd>PoptoolsRecentFiles<cr>
If you don't like the default behavior, there is room for some customization.
The process is very easy. All you have to do is to set some entries in
the g:poptools_config
dictionary.
However, keep in mind that you may also change the plugin behavior by through
Vim the options :h 'wildignore'
, :h 'wildoptions'
and :h 'path'
.
You may not want the preview window in every case. For example, you want it when you grep but not when you open recent files. If that is the case, do as it follows
g:poptools_config = {}
g:poptools_config['preview_grep'] = true
g:poptools_config['preview_recent_files'] = false,
Syntax highlight in the preview window can be handy, but it may slow down the
user experience. You can avoid using syntax highlight in the preview window by
setting g:poptools_config['preview_syntax'] = false
. This is useful in case
you are encountering troubles when using the preview window. The match are
still highlighted.
You can filter the results either in a fuzzy or in an exact fashion. You choose
it by setting g:poptools_config['fuzzy_search']
to true
or to false
.
It follows an example of configuration:
g:poptools_config = {}
g:poptools_config['preview_syntax'] = false
g:poptools_config['preview_recent_files'] = false
g:poptools_config['fuzzy_search'] = false
To see the whole list of keys allowed in the g:poptools_config
dictionary,
take a look at :h poptools.txt
.
These commands take into account the setting of :h 'wildignore'
,
:h 'wildoptions'
and :h 'path'
options, so if you want to include/exclude
some search path, you must adjust such options.
By default, hidden files are excluded. If you want to find them, then you must
add .
at the beginning of the search pattern, e.g. use .git*
to get e.g.
.gitignore
.
Hidden files are searched in non-hidden folders. To find files in a hidden
folder, you must first cd
into such a folder. For example, cd ~/.vim
followed by PopupFindFiles
will search files inside the .vim
folder.
They use the internal :h vimgrep
and the external :h grep
. However, The
user interface is the same. The results appear both in the quickfix-list and in
the popup.
By default, the option 'grepprg'
is set, as it follows:
# Windows
&grepprg =
'powershell -NoProfile -ExecutionPolicy Bypass -Command '
.. '"& {Set-Location -LiteralPath ''' .. search_dir .. '''; findstr /C:'''
.. what .. ''' /N /S ''' .. items .. '''}"'
# *nix
&grepprg = 'grep -nrH --include="{items}" "{what}" {search_dir}'
where the values of {what}
,{files}
and {search_dir}
are replaced by
user input.
You can also configure your own 'grepprg'
command through the keys grep_cmd_win
and grep_cmd_nix
of the g:poptools_config
dictionary and you can use the
placeholders {search_dir}, {items}
and {what}
. For example, you could set
the following:
g:poptools_config['grep_cmd_win'] =
'powershell -NoProfile -ExecutionPolicy Bypass -Command '
.. '"& { findstr /C:''' .. what .. ''' /N /S '''
.. fnamemodify($'{search_dir}\{items}', ':p') .. ''' }"'
If you define your own 'grepprg'
, then the elements in the quickfix shall
contain the buffer number, the line number and the text. You can verify it by
running :echo getqflist()
. The returned dictionaries must have the keys
bufnr
, lnum
and text
. If that is not the case, then you need to set
'grepformat'
adequately. See :h 'grepformat'
for more info.
To find hidden folders with PopupFindDir
command, just add a .
in front of
the search pattern, e.g. .git*
. That will return e.g. .git/, .github/
,
etc.