The way I'd like NVIM to work
I have spent a decent amount of time trying to get familiar with different nvim plugins. You can find my configuration files here. With some basic feeling on how things could work, I decided to write down my expectations on how things should work. In another word, I’d like start with my expectations, then work backwards to get my configurations right. Oh my god, I can let AI implement it if my writing here is super good.
:Files
This is about finding the right files to view or edit. As of now I have two keymappings for that:
<leader>ffthat calls:Filesfrom fzf.vim.<leader>fFthat calls:Files <cwd>from fzf.vim.
I have two variants because I either want to find files globally or in the directory of current buffer (and its sub-directories).
This isn’t exactly how I’d like it to work. The major flaw here is I can’t
specify the file pattern I’d like to search easily. I either have to yank the
file or directory name into a register, and then paste to file picker popup
window. This 3 steps (yank + <leader>ff + paste) file search should be
simplified.
:Files with selected text
Often times, the file or directory name is right there, so the extra step to yank it then pass it to fzf should be automatic. In the following example of terraform file:
module "images" {
source = "../images-azure"
os = "${var.os}"
}
../image-azure points to a parent directory. To navigate to images-azure
directory and see all the *.tf files there I can instead:
- Enter visual mode.
- Select
images-azure. - Type
<leader>ff.
This should open up the fzf file picker but with images-azure as the pattern
to search.
The mnemonic for ff is find files.
:Fg
This is about finding the files that contain the given text pattern. As of now I have two keymappings for that:
<leader>fgthat greps globally.<leader>fGthat greps the current buffer’s directory.
This has the same limitation as I mentioned in :Files. The text that I want to
search has to be yanked, and then copied to the interactive prompt. This should
be automatic via:
- Enter visual mode.
- Select the text to grep.
- Type
<leader>fgor<leader>fG.
This should set my selected text to the initial pattern. I of course should be able to update the text pattern later.
The second aspect of :Fg is to tell what files to grep. Instead of grepping
all the files, I can, for example, tell it to only search *.tf files. As this
may involve some typing, I actually won’t prefer using a keymapping for this
especially when :Fg is already short enough. If I already have some text
selected in visual mode, then :Fg *.tf should limit that search to only *.tf
files.
To search current buffer’s directory, we can create a variant as :FG that only
searches current buffer’s directory.
The mnemonic for fg is file grep.