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
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.
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'.
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.
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. :)
I would like to have vim fill a short sequence of characters into a longer string in insert mode. Example, say I write the word "sub" and it writes "subroutine" as soon as I press space. The problem I find is that when I use :imap sub subroutine, every time I start typing sub, the cursor does not continue moving, but hangs in the same position waiting for more keystrokes in order to decide what to do. I find this behavior annoying, although not wrong (it does what I need).
Is there a way to have vim continue typing single characters, and eventually replace ?
Just try to use abbreviate :ab sub subroutine
Search the web for "vim completion" (or the help for "completion"). The feature is in v7.x, but you may want to change the keystrokes with ìmap.