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

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

Related

How to change a word in Vim (and all of its other occurrences)

I frequently use the combination c-a-w to change a word in Vim.
Are there any similar means by which one can quickly also change all other occurrences of said word in the specific file?
Use gn option for this purpose, in my case, I have a slightly different version of it
" allows me to use a smarter cgn
nnoremap c* *<c-o>cgn
nnoremap c# #<C-o>cgn
Now when you have to change a word many times, as long as you have not so many of it, because in this case, a classical substitution would be better, just press c* and then press "dot --> ." to change the next occurrencies of it.
If you want to see how awesomeness gn can give us have a look at: Operating on search matches using gn (vimcasts)
You could try:
%s/<CTRL-R><CTRL-W>/NewWord/g
<CTRL-R><CTRL-W> means keep control key pressed and hit R and W.
This copies the word under the cursor to the command line.
See :help c_CTRL-R_CTRL-W.
The main command for replacement of all occurrences is :substitute. Unfortunately, being an Ex command, it doesn't integrate too well with the single-word replacement (e.g. caw) in normal mode: Though you can insert the previously replaced word into the command-line with <C-R>", you still have to enclose it in \<...\> to enforce a whole word match, and also escape any special characters inside the word.
That said, there are plugins that offer help in that area. One of them is my ChangeGlobally plugin, which offers a gc{motion} alternative to c{motion} that then applies the change (or deletion) to other matches in the same line or entire buffer. (The plugin page has links to alternative plugins.)

All occurrences of text between quotes (like * but for the whole text, not a single word)

When I edit XML-files I sometimes want to jump to the next occurrence of text between quotes. For example, when my cursor is on my.attr in attr="my.attr" I want to jump to the next occurence of my.attr. I want to do it via some key combination (like Shift + * which is for words occurrences). Is is possible?
You can create a visual selection of the attribute value inside double quotes with vi". Then, there are several plugins that implement the * command for visual mode (usually by overloading the * command), i.e. they search for the next occurrence of the selected text. One such plugin is my SearchHighlighting plugin. (The plugin page has links to alternative plugins.)
Related plugins
If you want to change all attribute values (without constructing a :%s/ substitution), my ChangeGlobally plugin provides a gc{motion} and {Visual}gc command that does that.
I would yank the text inside the quotes with yi" (only works if the opening and closing quotes are on the same line) and then /<C-R>". (The <C-R> means CTRL-R, not 5 characters.)
This gives you a chance to modify the pattern before submitting it; as #Kalanidhi pointed out, you may have to escape some special characters. It uses the same i" text object as in #Ingo Karkat's answer.
If your text is short, then you can edit the command line with the arrow keys, but if it is long you may want to edit it in a command-line window with <C-F>. (Alternatively, if you are thinking ahead, use q/ instead of /.)
:help y
:help text-objects
:help c_CTRL-R
:help cmdline-editing
:help cmdline-window
You can use in command mode type /<exact pattern> if any special character then escape the special character like \
For example In command mode /"my\.attr"
So only search the exact pattern. N or n to move forward and backward .

How can I use the commands defined in this vim tip?

I am looking for a way to use f followed by some character to jump to the next uppercase letter.
I ran across this question and want to use the accepted answer, since that did not appear to have any dependencies.
However, after I added the lines into my .vimrc, I cannot figure out how to actually jump to the next uppercase character.
I tried Ctrl-Right and Ctrl-o, and both orderings of them, but I could not jump to the next uppercase letter in the line. I also read the actual vim tip, but that also does not explain how to actually use the commands.
What is the correct sequence of commands, and in which mode, to actually jump to the next uppercase letter?
Does it have to be the find command? What about typing /[A-Z]? It'll find the next upper case character (even if it's on a different line), and it's fast to type. Pressing n will take you to the next one without retyping the command again.
What you found in the other answer was a macro command. VIM has a rich macro language that allows you to define functions. You can run a function by typing a colon and then its name.
Of course, typing :findNextCapitalCharacter is a bit long to type. You can use map to define a key macro that will basically type the letters for you to find the next command. I like prefixing my mapped macros with some character like %, so typing %c will find the next capital character.
Further Explanation
I'm currently just doing /\u, but I still want to know how to use the macro in that answer for my own learning. In the case of those macros, what is the actual means to invoke the macro command?
You're way ahead of me! I didn't know about \u being uppercase.
Looking at the answer, I see they're not defining a macro, but doing key mapping. Here's a quick intro:
In command mode (that's where you can't type in anything into your file, but where you can use commands), type in :map #$ iHello World and press return. Now, still in command mode, type #$. You'll see that VIM typed iHello World for you. The i put VIM into insert mode, so it could type in Hello World That's mapping!
In VIM, you have special map modes depending on the mode you're in. In the original VI, you had two modes: Command and Insert. In VIM, you have Command, Select, Visual, and Command-Pending modes. The different map command depend upon the mode. Type :help mapmode into VIM and press <RETURN> to see about the various map modes and their VIM commands. This will be VIM help manual sections 1.3 to 1.5. Read it thoroughly to understand what the different map command mean.
What the accepted answer is doing is entering the maps three different times, once for each mode. There are two different maps (one search to the previous and one search to the next), so six all together.
The accepted answer is mapping Cntrl-Left Arrow <C-left> and Cntrl-Right Arrow <C-Right> to each of these mappings. Much like I mapped #$ to Hello World.
Setting g:camelcase is setting a global variable called camelcase to a string. If the string is A-Z, it will be for just capital letters. If it's A-Z0-9, it's for capital letters and numbers. You should only define one instance of this variable.
I think you're problem is that you're typing in <C-Left> for the map. What you're suppose to type is ^V^-> where ^V is Ctrl-V and ^-> is Ctrl-Left Arrow. When you type that in, the map command will change those into <C-Left>.

How to keep my own CR in Vim with automatic format?

I used set fo+=a in Vim to enable automatic format when typing.
With that set, the <CR> I pressed will be erased when I continue to type, if the length of current line is less than lw, and that is not what I want.
What I want is:
Still able to add a <CR> automatically if the line is longer than lw.
When I type a <CR> manually when the line length is less than lw, I don't want that <CR> erased when I continue to type.
Thanks.
You can't. The format option "a" is designed to reformat your paragraph every time your paragraph is changed, so there's no way for you to keep any single line breaks inside your paragraph, regarding the definition of "paragraph" in VIM.
If you only need to be able to wrap long lines while typing, you don't need option "a". Option "t" is already quite sufficient for your case.
t Auto-wrap text using textwidth
If you are fine with using trailing spaces to indicate that a paragraph continues (by default it only ends on an empty line) then you can also do
set fo+=w
. Then to keep vim from joining lines all you need is to end it with something other then a space.
Note: this is not going to change the meaning of the paragraph for motion commands (in fact, there is nothing that can do change it).

Change delimiters for navigating word-wise

When programming/writing I heavily use word-wise commands, for example "move to the left/right by one word", "delete next/last word" by pressing Ctrl (+left,backspace...).
The problem I have is, when the text I am editing contains symbols which will not be recognized as words, therefore ctrl + right will jump over a sequence of symbols AND a regular word after that.
Ideally I want to be able to set the delimiting characters for word-wise operations to space, tab, newline and opening and closing brackets - maybe also arithmetic operators (similar to how Eclipse handles it).
I am using Linux. Do you know any way how to change my settings system-wide or alternatively for xterm and (g)vim individually to achieve this?
Most likely, system-wide won't work. VIM is easy, you can set the characters that define the identifier using the iskeyword setting. In your case, there is too much in it, and you need to remove the ones you do need, or redefine it by adding the ones you do want. eg: :set isk=9,32,50-51
This will set keyword detection to spaces, tabs and parentheses.
However, in VIM you can jump based on word and WORDs, where the first is defined by the abovementioned iskeyword setting, while the latter will jump over all non-blank characters. Maybe, that's the motion you want. You can read more about this in the help (:help w).
Instead of holding down the control key and pressing the left/right cursor keys, why not use Vim's normal mode word motion commands?
w/W - move to start of next word/WORD
e/E - move to end of next word/WORD
b/B - move to beginning of previous word/WORD
ge/gE - move to end of previous word/WORD
You can read up on the difference between a word and a WORD by running :help word.

Resources