How to keep search window? - neovim

Disclaimer: I don't know all the correct terminology here. When I say "window" it might be "quickfix modal dialog" or something.
I am using Neovim (through Neovide) and have these settings to enable search via the fzf plugin, by way of ripgrep:
" Search / Grep
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
set grepprg=rg\ --vimgrep
" set ctrl-p similarities to open files
nnoremap <silent> <C-t> :Files <cr>
nnoremap <silent> <C-p> :Files <cr>
nnoremap <silent> <C-b> :Buffers<cr>
nnoremap <silent> <C-M-h> :History<cr>
" disable preview window
let g:fzf_preview_window = ''
In my environment vars, I have FZF_DEFAULT_COMMAND set to:
rg --files --hidden --glob "!.git/*"
When I do something like :Rg fn I get a popup window that looks like this:
Here's the problem: when I hit enter to one of the lines to dismiss the window and go to the target file to make changes, I then want to bring the search window back up after I'm done.
I can hit : and then arrow up to re-run the search, but that can be pretty annoying, especially when there are many results and I want to keep the cursor around where it last left off. When I try :copen it's just empty.
Is there a way to re-open the last search in a window, preserving the state? (I understand the search results will be stale if I changed something... that's fine)
Aside for the specific question - I'd appreciate tips for working with search in the Neovim UI, for someone coming from GUI editors like VSCode.
Thanks!

Related

How to remap <cr> to go to line number in VSCodeVim

In vim I used to map the enter key <cr> to go to line number instead of the letter G using the following settings
nnoremap <expr> <cr> v:count == 0 ? "\<cr>" : "G"
I tried to achieve the same result in vim for VSCode but I couldn't.
Is there a way that manage me from doing so without enabling the experimental feature neovim integration inside VSCode

How do you use <TAB> to cycle through completion suggestions with ALE?

When using Ale, I'd like to use the Tab key to cycle through completion suggestions. By default, the arrow keys do it. What are the various configuration options for cycling through the suggestions as well as selecting the correct completion?
Could do something like this:
inoremap <silent><expr> <Tab>
\ pumvisible() ? "\<C-n>" : "\<TAB>"
Essentially, when you hit tab in insert mode, check whether the popup is visible, and if it is then send Ctrl-n (to go to the next match), otherwise send a tab.

vi command line editing key bindings - previous command

I use the vi editor on the command line, and I really like it.
I use
set -o vi
to set the bindings.
The only thing is that I have to use the up and down arrows to cycle through the
previous executed commands.
In the emacs key bindings it was Ctrl+p to get to the previous command. It is the one emacs binding I miss.
I have been looking for something like it vi - but can't find it. My search gets diverted to the text editing vi binding for previous command which is held in " : " or hitting Ctrl+F to get a command window. I am using vi on the command line instead of emacs. There has to be something.
Is there something comparable in the vi command line ?
Using the Up / Down arrow keys is driving me nuts.
Actually I found the answer on this on this site:
Working Productively in Bash's Vi Command Line Editing Mode (with Cheat Sheet)
Make sure set -o vi is set to 'on'. Hit Ctrl+[ or escape to get to command mode. Then tap k go up the history and j to go down. It is so intuitive that I imagine most vi power-users discover it without trying, without help.
Thanks.

use :tjump instead of :tag vim on pressing ctrl-]

in vim,
when i press ctrl-]
1) the usual behavior:
it goes to the first matching tag with the word under the cursor,
after that we need to do :tjump separately to see a list of all matching tags and then jump to the desired tag.
2) what i want is:
vim should search the tag file,
if there are multiple matches, show me a list of all the matching tags
if there is one match, simply jump to the matching tag
(just like :tjump does)
this behavior(2) already happens when we use g-ctrl-], but i want it to happen with ctrl-]
i have seen behavior(2) using ctrl-] in some vims in some linuses.
please tell me how i can obtain behavior(2). in other words,
please tell me how i can make ctrl-] to behave like g-ctrl-] using .vimrc or whatever
This will map <c-]> to g<c-]> for both normal and visual modes.
nnoremap <c-]> g<c-]>
vnoremap <c-]> g<c-]>
I suggest you map g<c-]> to <c-]>. In other words just swap the commands.
nnoremap g<c-]> <c-]>
vnoremap g<c-]> <c-]>

How do I remap META to ALT?

I am using emacs in Ubuntu. How can I remap META to the ALT key?
If you run emacs in a gnome-terminal, the gnome-terminal may be capturing your alt key to open the gui menu (File, Edit, ...). You can change this behavior by selecting Edit >> Keyboard Shortcuts ..., and unchecking `Enable menu access keys ...'.
On my system, Ubuntu 9.04, this lets alt serve as meta for emacs.
Usually Meta is mapped to the Alt key by default.
What is displayed in the echo area at the bottom of the Emacs window when you type Alt+X? If you see M-x then Alt is working as Meta.
Way back when, it did seem that the META key was difficult to map to the ALT. At that time I had to use xmodmap, and these were the things I had to put in my .xmodmap file. Some variation of the following always worked (it depended on the system). My .xinitrc file would have xmodmap read in the file.
!! Note the `!` are comment characters.
!! suggested to make Emacs work under VNC
keysym Alt_L = Meta_L
keysym Alt_R = Meta_R
!! xmodmap -e 'keysym Alt_L = Meta_L' -e 'keysym Alt_R = Meta_R'
!!
!! some environments still can't handle alt key properly
!! add this:
!!
clear Mod1
add Mod1 = Meta_L Meta_R
!! or
!! xmodmap -e "clear Mod1" -e "add Mod1 = Meta_L Meta_R"
Use xkeycaps to look at your keyboard mapping and swap the META and ALT modifiers, or just swap the entire keys. Because GNOME has some assumptions about which keys have META and ALT modifiers, it'll probably make your life easier to swap the keys entirely.
xkeycaps should be available as an ubuntu package.
If using a Mac, open up terminal then navigate to Terminal > Preferences. Under the profiles tab, check the checkbox on Use Option as Meta Key. See screenshot
That should do the trick.