vim omnifunc popup on keypress [duplicate] - vim

I have a vim script that uses a one line window to get a filename pattern from the user. This pattern can be completed to a full filename from a database if you press CTRL-X CTRL-O. Now the only problem is that you have to press the auto completion shortcut by yourself. But I want the auto completion to work incrementally so that for every character you type it automatically gets updated (think about the CTRL-R file open dialog in Eclipse).
Is there a way to use an autocommand or some kind of callback to call the function behind CTRL-X CTRL-O for each character the user is typing in this particular window?

Austin is on the right track, but just with the wrong event. Take a look at the CursorMovedI event of autocmd. Basically, it'll fire any time the keyboard cursor moves while in Insert mode. Type a character? Cursor moves, and the event is fired.
Keep in mind this is a bit heavy-handed for your use, because the cursor can move due to other things than typing or deleting characters. The user could use the arrow keys to move back where they want to edit. You'd be popping up the completion with every move.
I can't find anything in the help about window-local autocommands, but buffer-local exists, so that might be close enough.

Try - and modify if necessary - this plugin: http://www.vim.org/scripts/script.php?script_id=1879
I'm a happy user.

You should look at :h autocmd. I believe the InsertChange event could be used to do what you want.

Related

How to call function without leaving insert mode?

I am trying to create a plugin for vim like ctrlp and I need some help. First of all I want to place input field at the top of the screen so
Is there a function similar to input() but which can place input field at the top?
Friendly speaking, I have already started to realize my own input field and there is an issue while editing text. I have found a backspace option very useful to prevent deleting prompt text ("Files> "). I just put this text to the buffer and then start insert mode. To my regret I cannot use this option because I have complex logic to control buffer and I always need exit insert mode to call functions. Instead of backspace I need remap <BS> to something like this <C-o>:call backspace()<CR>
function backspace()
" checks if deletion is possible
x
endfunction
This works but there is a cursor flashing which disturbs me. Insert mode makes buffer modified and there is a mark * in tabline. It can be hidden call setbufvar(bufnr('%'), '&mod', 0) but it works quite slow and the symbol appears from time to time. I use TextChangedI event for this.
Is there an option to disable monitoring buffer change?
The most important question is how can I get more freedom in insert mode? Is there a way to calling function without leaving this mode?
Is there a function similar to input() but which can place input field at the top?
No. The command-line is at the bottom and there's nothing you can do about it.
Is there an option to disable monitoring buffer change?
Yes. See the last paragraph of :help 'modified'.

How show wildmenu automagically, without the need to press <Tab>?

In my Vimrc, I have this set:
set wildmenu
set wildmode=full
set wildignorecase
When you are typing like NERDTree, and press Tab you see the suggests results in your statusline. Looks awesome, right?
I would like to have a function, that every time you press a character in the command, the Tab is automatically pressed. So every time, you type a character, you see the suggested commands in the statusline. Like Emacs M-x.
I looked in help in the autocommands, but none of the events described the event (pressing characters in command line).
Anyone have a idea which event I mean?
There is no such event. You're probably thinking of InsertCharPre, but that's limited to insert mode. You would need to override every printable character in command-line mode via :cmap, but that could have other side effects, or interfere with some plugins.
Better think hard whether you really need this. The wild menu is modeled after shell completion, and that has to be explicitly triggered via <Tab>, too.
Perhaps you want wilder.nvim.

How to navigate results (candidates) in Unite.vim?

After a search in unite.vim, you open a candidate. Is there an easy way to jump to the next one without having to run the search command again? Similar plugins (ack.vim, git-grep) use the quickfix window, so you can type :cn and :cp to jump to next/previous results. Is there anything similar in unite.vim?
Thanks!
I haven't managed to find a way to put results into the quickfix or location lists, though I'm sure you could extend Unite to include that action.
Meanwhile, this little exerpt from the Unite documentation can help you re-open the Unite buffer you just recently had open:
:UniteResume [{options}] [{buffer-name}] *:UniteResume*
Reuses the unite buffer named {buffer-name} that you opened
previously. Narrowing texts or candidates are
as-is. If {options} are given, context information gets
overridden.
Note: Reuses the last unite buffer you used in current tab if
you skip specifying {buffer-name}.
I use this in the following way in my vimrc:
" Press <leader>ll to re-open last Unite buffer
nnoremap <silent><leader>ll :<C-u>UniteResume<CR>
Another useful snippet from the docs:
-no-quit
Doesn't close unite buffer after firing an action. Unless you
specify it, a unite buffer gets closed when you selected an
action which is "is_quit".
-keep-focus
Keep the focus on a unite buffer after firing an action.
Note: This option is used with "-no-quit" option.
For example, you could bind
nnoremap <silent><leader>lg :<C-u>Unite -no-quit -keep-focus grep<CR>
To be able to press <leader>lg to grep through your source files, without closing or de-focusing the Unite buffer when you select an item.
Good news, everyone! I created an issue-724 with your request in Unite repo and it has been implemented in the blink of an eye! Glory to Shougo!
From the docs:
:UniteNext [{buffer-name}] *:UniteNext*
Do the default action with next candidates in the unite buffer
with {buffer-name}.
You can use it like |:cnext|.
:UnitePrevious [{buffer-name}] *:UnitePrevious*
Do the default action with previous candidates in the unite
buffer with {buffer-name}.
You can use it like |:cprevious|.

Traversing directories with vim file name completion in insert mode (Ctrl-X Ctrl-F)

I’m trying to use vim’s compl-filename feature (Ctrl-XCtrl-F) to complete paths in INSERT mode, but I can’t work out how to traverse into directories without (temporarily) ending the completion mode:
Let’s say I want to complete the path /etc/sysconfig/network-scripts/ifup.
I would like to be able to do something like:
/eCtrl-XCtrl-F
/etc/
/etc/sysCtrl-F
/etc/sysconfig/
/etc/sysconfig/netCtrl-F
/etc/sysconfig/netconsoleCtrl-N
/etc/sysconfig/networkCtrl-N
/etc/sysconfig/network-scripts/
/etc/sysconfig/network-scripts/ifupCtrl-Y
/etc/sysconfig/network-scripts/ifup
The issue is, as soon as I start typing* after a path match (like /etc/), it ends file name completion. I would like it to stay in file name completion, so that I can still use Ctrl-F, Ctrl-N, etc. Since it ends completion, I have to type Ctrl-XCtrl-F again to restart it, and the helpful completion popup menu disappears in the meantime.
Is there an option I can set to change this?
* By ‘typing’ here, I am referring to characters in 'isfname' -- of course, typing other characters (like space or punctuation) should not continue file name completion.
I'm not sure exactly what you're saying, but you can just press Ctrl-XCtrl-F again on a directory while you're in the completion menu to expand it. You don't have to close out of the menu first. I just keep Ctrl held down and tap xf to traverse a directory, n and p to move up and down and w to go back up.
If you don't use :h i_CTRL-F then you could remap it. For example,
inoremap <C-f> <C-x><C-f>
Simple remap would be
inoremap / /<C-x><C-f>
So when you type slash(/) in insert mode you will get that auto completion popup :)
Place it in your .vimrc file (for vim) or in init.vim (for neovim)
Vim doesn't do auto-completion.
For that, you'll need a dedicated plugin like AutoComplPop or NeoComplCache
Please use insert "i" first before using cntr+x+f. I was in similar situation. :)

Calling omnicompletion for every keypress in vim

I have a vim script that uses a one line window to get a filename pattern from the user. This pattern can be completed to a full filename from a database if you press CTRL-X CTRL-O. Now the only problem is that you have to press the auto completion shortcut by yourself. But I want the auto completion to work incrementally so that for every character you type it automatically gets updated (think about the CTRL-R file open dialog in Eclipse).
Is there a way to use an autocommand or some kind of callback to call the function behind CTRL-X CTRL-O for each character the user is typing in this particular window?
Austin is on the right track, but just with the wrong event. Take a look at the CursorMovedI event of autocmd. Basically, it'll fire any time the keyboard cursor moves while in Insert mode. Type a character? Cursor moves, and the event is fired.
Keep in mind this is a bit heavy-handed for your use, because the cursor can move due to other things than typing or deleting characters. The user could use the arrow keys to move back where they want to edit. You'd be popping up the completion with every move.
I can't find anything in the help about window-local autocommands, but buffer-local exists, so that might be close enough.
Try - and modify if necessary - this plugin: http://www.vim.org/scripts/script.php?script_id=1879
I'm a happy user.
You should look at :h autocmd. I believe the InsertChange event could be used to do what you want.

Resources