I'm using the current PHP Storm EAP (138.1505) and IdeaVim 0.35.
Suppose I just want to type:
print_r($foo);
I press i to go into Vim insert mode.
I type p r and I can choose print_r via the autocomplete.
It'll add open and close braces () for me.
I start typing my variable, it'll let me autocomplete that too.
At this stage I have print_r($foo) with my cursor positioned before the closing bracket.
What I'd like now is a single key combination that'll finish the line for me - i.e. add a semi-colon and a carriage return. At the moment I either have to type );[return] by hand as if the autocomplete wasn't there, or for some reason I've got in the habit of doing esc to leave insert mode then A to continue at the end of the line and ;[return][esc]to finish it off, which is even longer.
Any better way?
I don't use PHP Storm. but I do use Intellij + ideavim.
Here I can press Ctrl-Shift-Enter to complete a line. It is a kind of default setting. You can find it under menu: Edit: complete current statement
You may want to give it a try.
You can add this line to ~/.ideavimrc:
imap <C-e> <Esc>A;<CR>
Replace <C-e> with your desired key.
Related
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.
I am trying to use the vim autowrap functionality to automatically wrap my paragraph into lines no longer than 80 letters in real time as I type. This can be done by set textwidth=80 and set fo+=a. The a option of the vim formatoptions or fo basically tells vim to wrap the entire paragraph while typing.
However, there is a very annoying side-effect, that I can no longer break a line by simply pressing enter.
This is a sample sentence.
Say for the above sentence, if I want to make it into:
This is
a sample sentence.
Usually I can just move the cursor to "a" and enter insert mode and then press enter. But after set fo+=a, nothing will happen when I press enter in the insert mode at "a". One thing I do notice is that if there is no space between "is" and "a", pressing enter will insert a space. But nothing else will happen after that.
So what do I miss here? How do I stop this annoying behavior?
You can run :help fo-table to see explanations of the options:
a Automatic formatting of paragraphs. Every time text is inserted or
deleted the paragraph will be reformatted. See |auto-format|.
When the 'c' flag is present this only happens for recognized
comments.
This means that every time you insert a character, vim will try and autoformat the paragraph. This will cause it to move everything back onto the same line.
I don't think you need to add a at all. I use neovim, but the behavior here should be the same. The default values are, according to the help pages:
(default: "tcqj", Vi default: "vt")
Try removing set fo+=a entirely from your .vimrc. Keep set textwidth=80. That should fix your issue.
EDIT: Once you have set textwidth=80, if you want to format an existing paragraph, you can highlight it in visual selection and press gq.
The following allows me to use the enter key to start a new line while setting the text width to be 79 characters:
set tw=79 "width of document
set fo=cqt
set wm=0 "# margin from right window border
After some exploration, I find a workaround that can solve the problem to some extent, though not perfect.
The basic idea is that when entering a line break, disable the auto-wrapping temporarily when sending <CR> and resume auto-wrapping after that. There are multiple ways of doing that. And the best one as far as I know is using the paste mode, since you don't have to exit insert mode when entering paste mode. So just make the following commands into any key binding you like in insert mode. The one I am using right now is inoremap <C-N> <F2><CR><F2>
The reason why I think this one is not optimal is that for some reason I cannot bind <Enter> in this way, but have to use another key.
If <Enter> or <CR> can be configured in this way then the problem is 100% solved.
I have a problem that have been bothering me for days now.
Whatever I do, I simply cannot place any single {,},[ or ].
Every time I try, it takes me up to the next or previous paragraph. I've looked it up and I can't find a good way to unmap it and finally have my azerty keyboard to behave correctly so I can peacefully code
In the normal mode, press 'i' to enter the insert mode.
And you can start to edit your file.
After everything is done, press the 'ESC' key and then ':wq' to save your modification.
Vim / vi has several different modes. This dates back to the times when you would edit using a teletyper, i.e. no "visual" representation of the data you are editing, no mouse etc.
With only the "usual" keys at your disposal, you need to navigate in the data, you need to insert data, and you need to execute commands on the data. Not so coincidentially, these are the three modes of Vim / vi, and in each mode, the keys do something differently.
By default, the editor starts in the "normal mode", which you will use to navigate, and enter the other modes from.
In this mode, ) moves you to the end of the sentence, ( to the previous sentence. } and { do the same for paragraphs, combinations of [ and ] work with chapters.
If you enter "insert mode" (most simply by pressing i in "normal mode"), you can enter all the above letters normally. You exit "insert mode" by pressing <Esc>. You will recognize "insert mode" by -- INSERT -- being displayed in the bottommost line of the screen.
If you are in "insert mode", and pressing any of the above keys does move your cursor instead of entering the corresponding symbol, there is some (broken) configuration at work. Check your ~/.vimrc, and if necessary, rename it and try again with a "clean" configuration.
It is next to impossible to do Vim / vi justice in the scope of a SO answer. It is very much an expert-friendly editor, not a novice-friendly one. You need to actually learn how to use this editor, but it is absolutely worth it in the long run.
In insert mode, you should be able to insert brackets without trouble.
In normal mode, those correspond to motions.
To go to insert mode from normal mode, press i.
See: :h object-motions
Alright, Problem Solved ! I had to uninstall and reinstall the Ubuntu bash on windows 10 multiple times and it worked ! Thanks for the help everone !
For instance, I'd like to use $ to move to the end of the line, without going through Esc for it.
Just $, and not Esc then $.
Is there a way?
One solution could be: press another key(/combo), say, Ctrl+Shift, do what I want in "temporary normal mode", then when I release those keys I'm back in insert mode... if that's possible.
If you wanna perform one normal mode command in insert mode you can use Ctrl+O and then normal mode command. So Ctrl+O$ will move you to the end of line in insert mode (like End or Ctrl+OShift+A).
Is there any particular reason why you want to go to the end of the line? Vi is built to mainly be operated in normal mode, not insert mode (especially when it comes to movement).
For example, if you wanted to go to the end of the line and start adding text, you would type A (or ESCA if you were in insert mode at the time).
If you wanted to go to the end of the line so you could add a newline, you could type ESCo to start a new line and place you in insert mode.
If you gave us more context as to what you are ultimately trying to accomplish, we may be able to come up with a more efficient workflow.
inoremap $ <ESC>A
give this a try. It may do what you want, but make inserting $ harder.
Ctrl + Right
map! <C-Right> <Esc>A
With the DelimitMate, it auto generates the closing parentheses. When I'm finished typing inside the parenthesis, what key strokes do I press to quickly go to the right of the closing parenthesis? (Right now I have to manually press ESC then 'a')
The idea of these auto-closing plugins (like the original feature implementation found in IDEs like Eclipse) is that you just type the closing character to go over it. The plugin should detect this situation and instead of inserting the character jumps over the existing, auto-inserted one.
If that's not working for you, there are several plugin alternatives on offer. The Vim Tips Wiki has a list of them.
With delimitMate, Shift-tab will jump out of the current delimiter and Control-G g will get you out of nested delimiters. No need to remap anything.
You could try auto-pairs's Fly Mode
eg:
( hello| world )
press ) at |
( hello world )|
If jump incorrect, use <M-b> to do the back insert.
eg:
(hello| world()
press ) at |
(hello world()|
press <M-b>
(hello)| world()
Repository: https://github.com/jiangmiao/auto-pairs
Plugin: http://www.vim.org/scripts/script.php?script_id=3599
add
let g:AutoPairsFlyMode=1
to .vimrc to turn Fly Mode on
You can do a custom map. I guess you want to go to the right of the closing parenthesis while you're in insert mode. Just add to your .vimrc this mapping:
:inoremap <F8> <ESC>f)a
In this way, while your in insert mode and you've finished to write inside the parenthesis, F8 will bring your cursor ad the right of the closing parenthesis.
If you want you can change the mapped key, using another key instead of F8.
As Kent said in the comment a more general solution would be:
:inoremap <F8> <ESC>%%a
Which will work for [ and { brackets.
I kinda agree with Atropo on this one: if you want to stick with DelimitMate then the least disruption to your workflow might be to make a custom imap to get to the other side of the auto inserted character.
Personally I prefer to have more control over where/when the characters are auto-inserted, and how I can navigate around the auto-inserted characters; UltiSnips or SnipMate does that for me. Maybe they're more what you're looking for.
If you typing on a new line, you try A which will append text at the end of the line.
I have autoClose installed. what I am doing currently is ("I" is cursor)
- (xxxxI)
- ( xxxxI )
- ( xxxxIxx )
- text (xxxxI) other text
- text ( xxxxI ) other text
- text ( xxxxIxx ) other text
I just make a mapping, to <esc>%%a then in above case, the cursor will move to (...)I..whatever
it doesn't work for quotes.
A little late to the party, but note that it can be done easily without any custom mappings. In insert mode, you can press <C-O> (a default mapping) to enter a "one shot" normal mode where you can enter a single normal mode command.
So to answer your question, what you could do is <C-O>a.