vim not accepting abbreviation insertion before text - vim

i have this problem: i have this in my _vimrc:
iab dd \mathrm{d}
and it works fine, except when I am editing a line and there is text on the right of the cursor (space or no space in between). Is there anything I can do to fix this? I couldn't find anything in the help files (or here!)..
thanks!
s.franky

This is not directly related to your question but regarding easy text completion, if you don't know it already, you should have a look at the SnipMate plugin.
It inserts snippets of code depending on the context by a simple press of <Tab> key.
There is already a Tex snippet file that you can easily expand with your own abbreviations.

Your solution works fine, except that I want this to work only after I press space (this is what is meant by non-word character, right? So, I am typing a non-word character, only it doesn't work in all cases)
I don't get it. Why does it matter that other text follows, if I still press space?
thanks though, this is much better than the previous one not working at all!
#chris morgan: oddly, it's working for me too, sometimes, in an empty document. If I load up a tex document (latex-suite package), it's impossible. But I m not sure it's latex-suite specific. Sometimes this happens for .txt documents, too..

abbreviations like this will trigger when you enter a non-word character. Maybe what you want is rather an inoremap?
From the documentation:
An abbreviation is only recognized
when you type a non-keyword character.
This can also be the <Esc> that ends
insert mode or the <CR> that ends a
command. The non-keyword character
which ends the abbreviation is
inserted after the expanded
abbreviation. An exception to this is
the character <C-]>, which is used to
expand an abbreviation without
inserting any extra characters.

Related

Add whitespace to current line in vim

I fairly often find myself in a situation like this:
I'd like to start typing on the line on which my cursor is currently. However, in order to get to the correct indentation level, I'd have to press TAB several times.
Usually I'd press ddO (delete current line and insert a new one above the cursor), which resets my indentation position to the right place:
But that seems like an odd way to go about adding the correct amount of whitespace.
Is there a better way that I'm overlooking?
When in normal mode, you can use cc or its synonym S. If you are already in insert mode, Ctrlf is the default key for this, but that can be changed by altering cinkeys (see :h cink for details).
See also this answer on the Vi/Vim stack
Kevin mentioned some shortcuts, but another method is <C-i> (indent) and <C-d> (dedent) in insert mode.

vim insert mode autocompletion by ctrl-p does not work after dot

In vim insert mode, if there is a word insert, and if I typed ins, then type ctrl-p, vim will auto complete the word to insert.
I remember in my last PC if I type data.ins then type ctrl-p, vim will auto complete the word to data.insert, but since I bought a new PC, vim does not auto complete data.ins, how to fix this?
By the way if I type b on t of the word data.insert, vim will jump back to d, instead of i, I need to jump to i
I suspect that the dot character somehow got to be a part of the iskeyword option. To verify this, you can look at the output of :set iskeyword? (note the final questionmark).
To fix this temporarily, you can do :set iskeyword-=.. To fix this permanently, find out where iskeyword is changed in your .vimrc.
The option iskeyword determines what characters Vim considers to be part of a "word". With a dot inside it, string like data.insert will be considered a single word, meaning you jump over them with a single w/b/e/... motion. Ctrl-p autocompletion looks whether the substring typed until now is part of a "word" in the rest of the document. Since you hadn't typed data.insert before, it doesn't find anything starting with data.ins. When you remove the dot from iskeyword, it will only look if something started with ins (like insert).
After you removed the dot, if you find yourself occasionally wanting to jump over the entire dotted name, you can use Vim's concept of WORDs (see :h WORD). You jump over WORDs using W/B/E/...

extra space added when going into insert mode in an abbreviation

I'm trying to create an abbreviation which replace typed text by what I want but also move the cursor and enters insert mode.
the ab is as following:
:abbreviate MSG `MSG(("")); <Esc>F"i
everything works fine except when entering insert mode, I have to extra spaces before the cursor.
I've tried then to add <BS><BS> but it's leading to delete the first quote. Same thing if I'm putting only one <BS> (which is really strange, it seems the second <BS> has no effect at all...)
I guess I'm missing something but I can't figure out what...
Thanks for your help !
A citation from Vim help system (:help abbreviations):
An abbreviation is only recognized when you type a non-keyword
character. This can also be the <Esc> that ends insert mode or the
<CR> that ends a command. The non-keyword character which ends the
abbreviation is inserted after the expanded abbreviation. An
exception to this is the character <C-]>, which is used to expand an
abbreviation without inserting any extra characters.
Example:
:ab hh hello
"hh<Space>" is expanded to "hello<Space>"
"hh<C-]>" is expanded to "hello"
So if you press <Space> after entering MSG a space is inserted after expanding your abbreviation.
To avoid adding a needless space you can invoke the abbreviation with pressing <C-]> after entering MSG or you can try elaborate a mapping like this:
:inoremap MSG `MSG(("")); <C-O>F"
But IMHO such a mapping is very inconvenient.
Another option may be to use use one of the many abbreviation plugins like this (first shown by Google).

How to skip over auto-inserted matching chars in vim insert mode?

When I'm in VIM insert mode, it wonderfully adds matching end characters. E.g. if I type " it will add another " immediately after the cursor. Similarly for parenthesis, braces etc. when programming.
How can I quickly skip over the inserted character, while staying in insert mode? The best I've found is to use the forward arrow key, but that's not conveniently located.
Accordingly, I either type the closing character, or I <esc>li (exit insert mode, move right one character, re-enter insert mode). This reduces the convenience of the auto-insertion quite dramatically, so I figure I'm missing something obvious.
(Note, for convenience I'm using the handy SPF13 curated collection of plugins and running MacVIM. Edit: This is the autoclose script providing the matching.)
There's basically no way to get out of an autoclosed pair that doesn't involve pressing at least one key.
The standard mechanism provided by all the autoclosing plugins is simple: type the closing character. You can also press <Right> or, if you are at the end of the line, <End>.
Maybe your plugin gives you another mechanism but you'll have to find out for yourself.
Whatever key you press, you'll still do at the very least exactly the same amount of typing as you'd do without autoclosing.
Autoclosing is not about saving typing, the only practical use of that feature is to prevent unmatched pairs. That's all and, I think, the "obvious" thing you are missing.
As you are using a SPF13 and don't know which plugins brought the mapping. There are two things that we can do
1) I usually esc followed by A. This will kept you in insert mode after the closed character if it is the last character. I usually prefer this over the second one.
2) You can circumvent the automatic closing by ctrl - v before the character, for instance ". This will not autoclose the corresponding character and you are responsible for the closing.

Vim: Eclipse-like Ctrl-Backspace and Ctrl-Del

In Eclipse, there is the nice feature of deleting the word until the next capital letter when you press Ctrl+Backspace. For example:
ThisIsSomeText
If you press Ctrl+Backspace, only "Text" will be deleted, where as in VS all the "ThisIsSomeText" will be deleted.
Is there anyway to implement the same in VIM?
If yes, is there similar method for Ctrl-Del also? That as, pressing Ctrl-Del at the beginning of the previous example will only delete "This", rather than all the "ThisIsSomeText".
I don't think it's a native vim feature, but I think this script might help (note: I haven't actually used it myself): http://www.vim.org/scripts/script.php?script_id=1356&rating=life_changing
Update:
Another script: http://www.vim.org/scripts/script.php?script_id=1905
This might do what you want:
nnoremap <C-BS> d?[A-Z]
There may be some fiddliness with the last character in the word. Also, you didn't mention whether you wanted it for Normal mode or Insert mode.

Resources