How to jump out of quote or jump out of code block with vim in vscode? - visual-studio-code

I'm learning Vim for few days and I have a question when coding with vim.
Let say I'm creating an object like this
const person = {
name: "Tu<my pointer after u character>"
}
What is the best way to move my pointer from after u character to after the double quote so I can keep writing my object
Another case is if I finish create object like this
const person = {
name: "Tu<my pointer after u character>"
}
How do I get my pointer to the line after the close curly bracket to keep writing code.
Some people say that I can escape the insert mode and using shift + A to go end of line but it takes 4 buttons to do that?
Thanks for answering my question.

Indeed the way to do it is to escape insert mode and use A to
[A]ppend stuff to the end of the line. To jump to the } in your code, there
are many many options, and which to use depends on the situation and user
preference, but I tend to use something like 3j to move 3 lines down (or
however many I need to move). And by putting the following in my vimrc:
set number
set relativenumber
I always know what number of lines I want to move.
Vim seems a bit weird for about 2 weeks (for me at least, when I started coding
in Vim) but after that it becomes automatic that if I finish inserting text for
any reason, I instinctively hit Esc. Many (most?) vim users remap
the some other key like CapsLock to act like Esc, since the Esc key on
modern keyboards is in an awkward position (unlike in the early days).
Once the 'modal' nature of vim becomes natural for you, things will fall into
place.
Oh, and it really helps if you learn to touch type 100% (i.e. never need to
look at the keyboard - even for numbers, punctuation, 'weird symbols' etc.)
Good luck!

In the first case, press <Right> or <End>, just like in any editor.
In the second case, press <Down> to move the caret after the }, then press <CR> (to open a new line) or <Down> (to move the caret to the line after the }), just like in any editor.
Going back to normal mode just for that is silly.
Note that you wouldn't have to deal with this without whatever you installed that closes quotes automatically.

Related

How to remap Tab key to two dots/period key presses

I want to map two dot/period key presses to Tab key in AutoHotkey script. I tried to map similarly as its shown for remapping semicolon key - on AutoHotkey forums, but it doesn't work. I tried following:
1. `..`::Tab
2. ..::Tab
AutoHotkey gives an error
.
I tried searching on AutoHotkey Remap docs, but couldn't figure it out. The period key is the one with the greater than mark and not the number keypad period key. See this: Dot/period key
Addition info/context in response to reply by user 0x464e:
Basically, I am trying to expand Emmet style abbreviations in devtools style sub-panel since the chrome devtools team wont implement it.
I am not a fast typist, so it's a pain to type complete property names. For example, if I want to type margin-top, (see the image), Chrome autocomplete brings up margin, margin-block margin-block-end etc.
Now, for margin-top, you need to at least type margin-t to get the autocomplete to show that property.
This is the case for many very common CSS properties like margins, paddings, etc., so autocomplete isn't great.
On the other hand, if I just type mt and have Autohotkey expand to margin-top, it's much much faster, saves me much time and keeps me sane.
Basically, I have setup some hotstring in .ahk script and they work too.
However, if I press mt followed by a Tab key press, Chrome's autocomplete takes over and hotstring fails, (try once to see the problem). Instead, currently I press spacebar, or . (period) to trigger the hotstring. It works, but the problem is it leaves a space or a dot with the expanded text. [see this].
So, that's the actual reason I wanted a double period key trigger to replace Tab.
It would be great if the hotstring trigger would work with a double period key, but doesn't leave the trigger character itself and then have send Tab so as to jump to the value input of the just expanded property.
You're not really looking for a traditional remap, which is why you didn't find it from the documentation.
Remapping is just simply remapping one key to another, but you're not trying to do that. You're trying to make some action do another action.
Anyway, what you're asking is doable, but there's loads of different ways it can be achieved with difficulties varying from simple to extremely advanced & complicated.
You'll need to specify things more clearly before this can be answered properly.
Biggest questions that pop into my head right away are at least:
Should this work everywhere, or just in text input fields?
How should the original functionality of . be preserved, if at all.
(What should happen after the initial . keypress?)
Should there be some timeout between the keypresses?
Etc, this is just what I could think of right away, but surely there's more.
Anyway, for now I can give a simple implementation with a hotstring:
:*?:..::{Tab}
So this is a hotstring with the * and ? options.
I'm guessing these would probably be pretty good options for this.
So what this does, is it presses backspace twice and sends a Tab if you type ...
This should be fine for text editors, but it leaves much to be desired (the points I listed above aren't considered since I can't know what you're looking for. This is just what a default simple hotstring can offer).
Looks to me like you don't actually want the additional mapping of .. to Tab, but instead just want to update your existing hotstrings to activate immediately (without waiting for an EndChar) when the hotstring is followed by ..
Normally, you might look to the Ending Characters option to create this functionality, but since you want multiple characters to trigger this, we need to look to other options.
I will be using the example of ::mt::margin-top for my sample implementation. Extend any changes I make to these to the rest of your hotstrings in the script you screenshotted.
Here are the changes I am making to this example:
Add your .. to the end of each of your hotstrings triggers. For example ::mt::margin-top becomes ::mt..::margin-top. However, at this present, this still requires some sort of ending character to be pressed in order to proc. Let's fix that in the next step
Add the Asterisk Modifier to the hotstring. From the docs:
* (asterisk): An ending character (e.g. Space, ., or Enter) is not required to trigger the hotstring.
Final code for ::mt::margin-top example:
:*:mt..::margin-top
And extend this * insertion and .. appendation to each of your hotstrings.
Hope this helped! Lmk if you need any more help or changes.

How to move cursor to a C++ function(method)'s name from its body in VSCode with VIM extension

I'm developing some C++ code with VSCode+VIM extension. From time to time I need to do this while reading code: say I'm inside a long function and I want to know who called it. The first step to do is to move cursor directly under function's name so that I can invoke some keystrokes to show references.
What I'm current using is to press "[" key twice which will bring me to the opening bracket of the function. Since I have to follow some coding standard, the typical scenario is like this:
ReturnType ClassName::FunctionName(
ParamType1 param1,
ParamType2 param2,
ParamType3 param3)
{ // <-- Cursor here
......
}
Then I need to press "k" several times to move cursor under "ReturnType", depending on how many parameters are there. Next, I still have to press "w" 3 times to eventually move cursor from "ReturnType", to "FunctionName".
As you can see, this is a little painful here. I've tried easy motion approach with VSCode VIM extension, this makes my life a little easier, but I'm looking for a even better one.
Any VIM trick or VSCode extension can do this decently?
Any help will be appreciated, thanks!
To avoid having to press k a variable number of times it's possible to make use of the fact that the ) is right on the line above, and use % to go to the matching (. The complete key sequence is [[b%b.
However the first b will go to the ( if there's nothing between the parentheses. [[ge%b can be used instead.
If there's something between ) and { (such as a const qualifier) [[?)<cr>%b would work (this solution is complex and perhaps only useful in a key binding?)
[[?(<cr>b works too as long as there's no parameter that contains an open parentheses (such as in FunctionName(int (*function_pointer)(int, int)) { ... })

After VS Code auto closes a quote, parentheses, or bracket, what key do i hit to move to the next position after that closing mark?

Sorry for roughly worded question.
I'll start typing something in VS Code like class="bob", and as soon as I type the opening " mark, VS Code will auto populate the closing " mark as well. Very helpful! BUT, once I'm done entering my string of information, I find myself having to adjust my keys on my keyboard to arrow right past the character that was automatically added, then hit a space, and continue on my coding way.
However this can interrupt my typing flow, as it would be just as easy if not easier for me to type the closing " mark myself without adjusting my hand from the default keyboard position.
This happens with other characters, too, not just quotes. Parentheses, brackets, single quotes, and similar items that show up in pairs.
When I watch videos of some people coding, they seem to gracefully whiz by those auto-added closing punctuation marks, so it makes me think there is something I'm missing in how I accept that automated input. Some way that is more zen like than using a right arrow.
Any guidance is much appreciated.
This worked for me;
Go to VS Code settings
Search "autoclose"
Disable "Auto Closing Tags"
Change "Auto Closing Quotes" from 'always' to 'never'
Change "Auto Closing Brackets" from 'always' to 'never'
You have several options:
Type the character that added automatically. For example, if you type { and automatically VS Code added } you can also type } to continue typing whatever you want. VS Code is smart to not doubling the automatically added character
Use End key
Use arrow right key
I think the VS Code team didn't find it needed to add some special key for this need, since all these options are also one key each.

Emacs tab not working

I have installed Emacs on my FreeBSD 8.2 box. Everything works fine but I cannot use tabs. When I am editing a file with emacs and hit tab, nothing happens.
What could be causing this?
If you're new to Emacs, you might expect pressing TAB to insert a literal \T. For various reasons, that's not the way most Emacs modes work. Most editing modes auto-indent your code as needed (<tab> is bound toindent-for-tab-command rather than self-insert). If the line you're TABbing on is already at the correct indentation level, it might seem that nothing happened.
Auto-indenting like this is easier and more consistent than manually indenting, but doesn't give you as much flexibility when it comes to deciding exactly how much whitespace is going to be present at the beginning of each line (and it also causes some problems when you want to, for example, tab-separate some fields). You can auto-indent a region using C-M-\ (that's Ctrl + Alt + \).
If you absolutely, positively must insert a literal \T into your code somewhere, you can do so using C-q TAB (press and release Ctrl + q and then press TAB). Typically, this is done to align columns in other editors; if that's what you're doing, it's probably a better idea to use align-regexp rather than tab literals.
In fundamental and text-mode I use C-<TAB>. I do not know which other modes this works in, but with few exceptions, plain text is the only time I need an actual \t character.

Multiline sentence in emacs

If I have a multiline sentence in Emacs it naturally overflows onto the the following lines. Now, if my cursor is at the beginning of such a sentence and I press the DOWN ARROW key, the cursor is placed at the beginning of the next sentence (which might be at 4-5 lines down), rather than on the next line itself (which other editors do). Same is the behavior of the END and HOME keys.
Is there a way in which I can change this behavior and get the cursor on the next line instead of the next sentence?
I haven't yet tried it myself, but I think what you are asking for is the default behavior for emacs 23. What version are you running?
You might want to check out the page Move By Visible Lines page on the emacswiki.
You might want to try auto-fill-mode or longlines-mode. To get either use M-X then type the command you want. Toggle them off the same way.
If that doesn't work you may want to examine the binding that is being applied to your down arrow. Type C-h k then hit the down arrow key.
It sounds as though the text is wrapping, so by definition (a line being a group of characters separated by a carriage return), it is moving down to the next line.
I agree it is a pain, however a lot of other editors also have this behaviour.
One way is to turn off wrapping:
M-x toggle-truncate-lines
You wont be able to see all of the text in the editor, however it will move down to the next line.