mapping shortcut in vim without hanging the cursor - vim

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.

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'.

Vim spell check automatically splits the screen

I typed z= underneath a misspelled word, and vim split the screen horizontally, thereby keeping the misspelled word in context, but also providing a list words to change the misspelled word from. Usually, this latter screen replaces the former screen when I hit z=.
I like this behavior, but can not replicate it. I must have hit something before z= but I do not know what.
The behavior you saw accidentally happens when there are only a few suggestions and they don't fill the entire window.
You can force a maximum size for the suggestion list (example: 20 suggestions) with
set spellsuggest=best,20
Now, as long as your window exceeds 20 lines, you will see the misspelled word in context, and the bottom 20 lines of your window filled with the suggestion list
I can't say what caused the behavior you saw, maybe it is some plugin.
But here are two options to stay in the context with spellchecker:
1) Use CTRL-X s in insert mode:
In Insert mode, when the cursor is after a badly spelled word, you can use
CTRL-X s to find suggestions. This works like Insert mode completion. Use
CTRL-N to use the next suggestion, CTRL-P to go back. |i_CTRL-X_s|
2) Use vimple plugin which turns few full-screen windows (including spell suggestions) into "overlays" (actually split windows where you can select the word you need).

Effective way to put ; at the end of line

Sorry for a noob question, but i find it struggling to just put a ";" at the end of line after writing a function. For example, I am coding in C and many time i need to write things like:
f(a);
what i usually type is (from normal mode, using bracket autopair-like feature):
if(a<ESC><SHIFT-a>;
and it need changing mode twice! Comparing to normal editor (sublime):
f(a<right>;
does anyone have more efficient way do do those typing? thanks for any help.
I think you have some "auto-close" plugin installed.
I have that kind of plugin too, and I don't press arrow keys either, since I don't have them on my keyboard. I have this:
" moving cursor out of (right of ) autoClosed brackets
inoremap <c-l> <esc>%%a
So with your example: it would be (assume already in INSERT mode)
f(a<ctrl-l>;
Thus, your fingers never leave the home row.
If you're a vim user, you can hit Shift-a.
Shift-a takes you from normal mode to insert mode, and starts your cursor at the end of the line.
(If you want to be an efficient vim user, you should remap esc to something like caps-lock.)
Comparing to normal editor (sublime):
f(a<right>;
Well… that's exactly how you would do it in Vim if you use Delimitmate or some other "autoclosing" plugin. Why do you insist on making things more complicated than they are?

Pasting text in vim. A tedious operation?

I've been using vim for somewhat longer than a year now and during this time I have never feel really comfortable with the way vim works with yanking and pasting text (or maybe it is just me not using it in the most efficient way)
For example, I have the word "World" yanked onto a register, and I want to paste it after "Hello". (Note that there are no spaces on either of the words). So, what I would do is
Hello
|
Place cursor here, and press "p". Then, what I will end up with is
HelloWorld
So, in order to avoid this, I have always to swith into insert mode, insert a espace, and go back into normal mode (or either make sure that the yanked word has a space before it). Be as it may, this is quite annoying behaviour I can't think of a solution for... Am I missing something here?
Suggestions will be appreciated.
Thanks
option zero
just live with what you have now.
option one
create a mapping for your workflow. for example
nnoremap <leader>p i<space><esc>p
option two
:set ve=all
then you could move your cursor to anywhere and paste
option three
you could in insert mode use <c-o> do normal mode stuff or <c-r> to get register values
I recommend option zero
You can use the Smartput : Adjust spaces and commas when putting text plugin for that. It modifies the p / P commands (this can be toggled on / off).

Abort keystroke sequence?

When using Vim I sometimes find myself midway through entering a key combination and change my mind or realise it's incorrect (I'm still learning).
For example I may have typed d, 4 and be about to press d in order to delete 4 lines and realise this is not what I want to do. How can I abort the current sequence of keystrokes?
Press ESC.
(no more text)
Ctrl+C also aborts the current command.
I prefer CTRL+[ over escape at all times, including aborting the current command. It's quicker and easier to type, particularly if you remap caps lock to ctrl.

Resources