Keyboard shortcut for folding code at current line in Sublime Text 3? - sublimetext3

Is there a keyboard shortcut that is equivalent to clicking the collapse arrow that shows up next to the line numbers?
CTRL-SHIFT-[ / CTRL-SHIFT-] acts on the whole class, way outside my chosen line. If I do CTRL-L on a collapsed line then CTRL-SHIFT-[ works for the uncollapsing a method. But I need to highlight the whole method to use CTRL-SHIFT-].
Is there no other way to simulate "click the arrow next to the line number" using just the keyboard?

Related

Left arrow and home key stop working in sublime python repl after making repl a separate window

Mac OSX 10.11, Sublime 3, REPL 1.0.30
When I open a python REPL (tools > SublimeREPL > Python > Python), it always opens as a new/current tab in the current sublime window.
While the REPL is tabbed, both the left arrow and home key function as they should (move cursor left per keypress, start of line). When I drag the repl tab to make it its own window, the left arrow and home keys stop working. All other arrow keys and end key function as expected.
If I press left arrow at the end of a line of text, like
def foo(bar):
instead of moving the cursor to the left of the colon, nothing happens.
However, I can see in the other sublime text window that the cursor is ghosting across that text. For instance, if the current position on the non-repl sublime text window is "Line 87, Column 13" pressing the left arrow key in the REPL window will do nothing in the REPL window, but change the cursor position of the non-REPL window accordingly (change cursor pos to "Line 87, Column 12"). Typing, of course, remains within repl, despite the left/home keys being mapped to the cursor pos in the non-repl window. Cursor position does not change with moving right with right arrow or end.
Does anyone know a way to fix this issue? Thanks for your consideration, at any rate.
I just submitted a pull request to the SublimeREPL repo that I believe should fix this -- so far I've been able to test it with ST3 under Windows 10. (ST3 build 3126, SublimeREPL 2.1.2.)
This said, the SublimeREPL pull request queue appears to be a bit backed up at the moment... I can plan to circle back once the fix has been merged.

Vim: Select all without scrolling away

is it possible in vim to select all lines in the current file, but leave the position where my cursor is unchanged?
Let's say I am currently at line 500 (of 3000) and want to quickly select everything (not yank), as my selection is simply set up to show whitespace characters. Can this be done without leaving my current line?
To achieve exactly what you like, you can press the following:
ggVG<Esc><Ctrl-O><Ctrl-O>
gg moves to the beginning of the file
V starts visual line mode
G moves to the and of the file (now you have selected the whole
file)
<Esc> leaves visual mode
<Ctrl-O> moves your cursor back to the prevois location (first to the beginning of the file, then the second time to your last position before pressing gg)
And if you like to select only the visible lines in you window (to not scroll away). You can use HVL instead of ggVG (H moves to the top of your window and L to the bottom).
You also could show whitespaces without using visual selection with something like this in your .vimrc:
set list listchars=tab:»·,trail:·,nbsp:·
This helps me to detect trailing whitespaces, and mixed (spaces/tabs) indentation.
usually pressing
ggVG
in normal mode will select all the lines, but it will leave your cursor at the last line of the file.
If you wants to highlights the whitespace characters then you can highlight this by using the below command in command mode (this white color chosen is for dark theme)
: hi ExtraWhitespace ctermbg=White guibg=White
Depending on what you are trying to achieve you can use something like :
%cmd
To apply the command to the whole file.
For example, %y will yank the whole file, %=will format the whole file, without moving your cursor. It does not really work if you do something like %d...
It is not a real selection though but rather a way to apply a command on the whole file.
To go further you can use something like
%norm Atest
To add 'test' at the end of each line. (Actually this is a bad example, because this command will move to the last line...)
It is not possible to have the cursor inside a visual selection. This caused by that, vim defines visual selection through two marks. As soon as you move the cursor one of the marks gets updated. Basically this means one of the marks is always lays where the cursor is(at least when using "v" to select). You cannot have the border in the middle of the region that the border defines :)

Vim Relative Numbering Reset on Scroll

When I scroll down a page the relative numbering is no longer based upon the cursor position.
Instead the line position relative to the top of the screen is displayed.
Sometimes I would like to delete or yank 200 lines and I dont want to have to do the subtraction and addition to figure out how many lines down my text is.
How can I show relative line numbers to the cursor even when scrolling?
I think what you want is, you scroll with mouse, and expect that vim keeps the cursor in original place. E.g. your cursor is at line 5, and you scroll down 5000 lines, you expect your cursor is still at line 5. That is, the cursor is out of the window.
AFAIK, the cursor won't go out of the window. That means, if you keep scrolling down, and the cursor line will be the top line of your current window. and the rnu are gonna re-calculated by the cursor line.
May be you could just explain what do you want to do. the cases in your question could be done by 200dd or 200Y but I guess it is not as simple as that.
You may want to find out the ending line by reading/scanning your text lines, and pick the line number (rnu), and do a xxxdd if this was the case. Here you should use normal line number. e.g. your cursor was at line 5, and you scroll down a lot, find the line you want to delete till from line 5. you could do :5,.d vim will delete from line 5 to your current line.
Or you can do 5, 23452d if you find out the lines between 5 and 23452 need to be removed.
If you can search your ending line by /pattern search, vim can do :.,/foo/d this will delete from current line till the next line, which matches foo.
You can still press V enter line-wise visual mode, and moving down by vim-motions. when it reaches the point you want to remove/yand press Y or d
You can take a look this Question/answer:
VIM to delete a range of lines into a register
At the end, I suggest you not using mouse in vim.
This is probably because the cursor moves down a page when you scroll down a page. In vim, the cursor is always on the screen. If you're scrolling down with, say, the mouse wheel, the cursor will just get "stuck" on the top line (modulo scrolloff) and stay there as you continue to scroll down.
Perhaps use ShiftV to start a line-based visual selection before scrolling, then use d or y on the selection?
I can confirm that the desired feature is available in Visual Studio Code (VSC) with the Vim extension installed. This is because VSC does not function like Vim by default and holds the cursor in place like other text editors do. This feature not only makes VSC bearable but proves more useful than vanilla Vim when coding large blocks of code also.
Additionally, VSC also allows for easy and language agnostic comment/uncomment toggling with <Ctrl> + / which is also very useful when used together with the above feature.

IntelliJ IDEA - multiple carets?

Sometimes I have to write Java class where I need to define multiple fields of the same type. For example, I know that I will need to duplicate private final String on the next 4 lines.
Is it possible to spawn multiple carets in IntelliJ editor, so I can type on mutliple lines at the sime time?
IntelliJ IDEA 14.1 & 15
You can press Alt + Shift and using the mouse left click you can put many carets.
E.g.:
will become
typing "added" only once.
If you want to have a continuous vertical line, it's enough to press Alt + drag your mouse vertically. If there are lines with a length lower than the current position, the vertical line will be broken (carets will be placed at the end of every line) if "Allow placement of caret after end of line" is disabled (in File > Settings... > Editor > General > Virtual Space).
Another way to add a continuous vertical line is to hit Ctrl twice and then press up or down arrow key (supported in JetBrains 2016.X products, and possibly earlier).
If you cannot get the shortcuts working, check what they're currently assigned to under Settings > Keymap Add or Remove Caret, Clone Caret Above and Clone Caret Below. If they look right and you're on Linux, your window manager may be capturing the combination, e.g., for Alt + window drag operations.
See:
http://blog.jetbrains.com/idea/2015/02/multiple-selections-in-editor-using-mouse/
https://www.jetbrains.com/help/idea/2016.3/multicursor.html
I think "Column Selection Mode" could help you. You can enable it in the context menu in the editor. Then you can select multiple lines and type same text at once.
Column Select
For Windows, you can use CTRL+CTRL(Hold)+↑ / ↓. For Mac, replace the CTRL with ⌘.
Change Multi-caret Hotkey
To add a custom Keymap, CTRL+SHIFT+A, type keymap and click on the one with Settings as subtext. Search for Clone Caret Above and Clone Caret Below.
I mapped mine to ALT+SHIFT+↑ / ↓.
Bonus
Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.
On Windows:
You can enable the Column Selection Mode (Alt + Shift + Insert)
And then Shift + ↑ / ↓ can select multiple columns
Hit Esc to go back to single cursor
Add/remove a caret: Alt + Shift + Mouse Click
Remove all carets: Esc
As for now(2018.9), you just:
Press middle mouse key to create a four-rows-high caret
Type what you want
Or,
Create the first line,
Press the "Duplicate entire line" key combination to create a new, identical line.
By the way, I think "multiple caret" should be like carets enabling me to edit different locations which are not necessarily vertically aligned. In Sublime Text you can press Ctrl and click. And in IntelliJ you can only "Clone caret up/down", that is to say, they are vertically aligned, which is not flexible.

Configure Macvim's text selection to not include character under cursor

Using macvim, when I copy a text selection, it always includes the character under the cursor.
For example, if the cursor is at the far left and I press shift-down arrow, it selects the entire line plus the first character of the next line (since the cursor is sitting over the next line's first character).
Is there a way to configure macvim to not include the cursor character in text selections?
Take a look at the selection option. By default it's set to inclusive, but you can change it to exclusive to make text selections act the way you want:
:set selection=exclusive
You can also set it to exclusive with the behave command:
:behave mswin
This also sets several other options, however, which may or may not be what you want. See the Vim help for the specifics.
:help :behave
:help 'selection'
I am guessing that shift-down arrow activates visual character mode, and moves the cursor down a line. If you are trying to select entire lines, you would be better off using visual line mode, which is activated from normal mode by pressing V (shift-v). This will select the current line in its entirety. You can then extend your selection to include the lines above and below using the k (or up arrow) and j (or down arrow) keys.
When using Vim, I think it is better to go with the grain rather than to fight against it. Don't expect it to work the same way as other text editors. Accept that the Vim way is different.

Resources