SublimeText3 Fold/Unfold all methods - sublimetext3

I am using SublimeText3 for C++ and Java. I am wondering if there is a way to fold all of the methods in a file / class, and then unfold them all, regardless of where the caret is. Or is there a way to list all the functions / methods.
Basically I would like to be able to enter a file and see all the methods at one quick glance.
Thanks

Using the Sublime Text 3 menu, you can find EDIT -> Code Folding -> which exposes the folding methods and will helpfully tell you the default keyboard shortcuts they are assigned to.
By default you press Ctrl+K, then Ctrl+1 to fold all subroutines. Then, to unfold all I would press Ctrl+K then Ctrl+J.
If this does not work for your file type / syntax, try Ctrl+K, Ctrl+2 and above to see if another folding level works for you.
Unfortunately for me, the proprietary code I work with required custom syntax and a custom function written in our in-house package to fold all of our functions (a new sublime command written in python and installed as a package).

More simple
Select the code and press:
Ctrl + Shift + [ to fold
Ctrl + Shift + ] to unfold
Updates
You can also select an element. Exemple:

Open the console (View -> Console or Ctrl`) with a source code file focused and enter the following commands at the bottom:
view.run_command("fold_all")
view.run_command("unfold_all")
to see their effect.
These commands can be bound with custom key bindings or put into the Command Palette for easy use.

Mac: Go to Edit/Code Folding as image bellow:
Details image

Related

Vim rename variable

Most people say vim is greatest editor.
But is there any way to rename variable as fast as sublime.
Example:
function f($items) {
$items;
....
$items;
}
In sublime:
Go to items variable
click ctrl+d 2 times
rename variable
In VIM:
Search for /items
cw
write the new name
"n" for next occurrence and then "." to repeat
In vim obviously the keystrokes are more.
Does anyone knows easier and faster rename variable method?
Thank you
There are few solutions:
Change command
Go to items and then hit:
*Ncgn{new name}<Esc>
And then you can . through rest of the files.
Plugin
I have written plugin which simplifies this flow sad.vim which simplifies above to:
siw{new name}<Esc>
And then you can . through rest of the occurrences.
Substitute
Select function body by vi{ and then call:
:'<,'>s/items/{new name}/g
Language Server
If your language has Language Server that supports renames then you can use one of the many LS clients for Vim out there and use the support from there.
The point is: in vim the moviment towards the target change point happens without touching the mouse, and it can also be made via terminal through a ssh session. You should also consider this. I have the following map:
:nnoremap c* *<C-o>cgn
Once you hit the variable just type c* followed by the new name, Esc and dot

How to map a key sequence to an IdeaVim key mapping

Currently, I'm attempting to organize some keyboard shortcuts for IdeaVim v0.48. I've run into a problem when I try to map shortcut "leader + ev" to an Intellij IDE action "ExtractVariable."
There is no official IDE action listed for extracting a variable, strangely enough, so I'm trying to map it to a function key. Here's what I put into my .ideavimrc:
set <F15> = ^[,
map <F15> <leader>ev
where my IDE shortcut for extracting a variable is "Ctrl + Alt + ,"
I've followed multiple guides on this, and still don't understand how to do it. Any ideas?
Answering my own question for others as the IJ Idea documentation is a little unclear:
The IDE action for "Extract Variable" is actually called "IntroduceVariable" if you want to call it from command mode (all other variable extraction actions begin with "Introduce" also). So to map this to a shortcut in IdeaVim, simply put this in your .ideavimrc:
map <what you want to use> :action IntroduceVariable<CR>

How to paste previously prepared code snippets in Vim?

In Windows, using the AutoHotkey utility, it's possible to write simple scripts to expand some text in an editor of choice (e.g. Visual Studio's editor).
For example, if in Visual Studio editor I type:
d1 [TAB]
(i.e. press the keys in sequence: d,1,Tab) the above "d1" text can be replaced with one or more lines of code snippets. The mapping between "d1" and the expanded lines of code is specified in a AutoHotkey script.
This is very convenient e.g. for demos; for example: at some point if I'd like to enter a whole function body, assuming that I associated it to e.g. "d3", I can simply press d3Tab on the keyboard, and I get the function body automatically pasted in the editor in current cursor location; and I can have different code snippets associated to different key combinations, e.g.
d1 --> DoSomething() function definition
d2 --> class Foo definition
d3 --> test code xyz...
Is it possible to achieve the same goal using Vim?
In other words, I'd like to have a set of code snippets previously prepared, and I'd like to paste each one of them in my currently edited source code file in Vim, in a way similar to what I described above.
Basic expansion can be done via the built-in abbreviations, for example:
:inoreabb d1 DoSomething()<CR>{<CR><CR>}<CR><Up><Up>
Read more at :help abbreviations.
snippets are like the built-in :abbreviate on steroids, usually with parameter insertions, mirroring, and multiple stops inside them. One of the first, very famous (and still widely used) Vim plugins is snipMate (inspired by the TextMate editor); unfortunately, it's not maintained any more; though there is a fork. A modern alternative (that requires Python though) is UltiSnips. There are more, see this list on the Vim Tips Wiki.
There are three things to evaluate: First, the features of the snippet engine itself, second, the quality and breadth of snippets provided by the author or others; third, how easy it is to add new snippets.
I have previously used snipMate that does something like what you're describing.
http://www.vim.org/scripts/script.php%3Fscript_id%3D2540

Vim: Have a paste operator (similar to c, d or y)

I'd like to have an operator-pending mapping for paste that works in a way similar to how d or c work.
Something so that I can do pi" which would mean "paste inside quotes".
Is there already a plugin for this or would I have to make one? If there isn't I'll make it, but I was curious in case I could save myself some work. :)
Of course I would make it using Kana's vim-operator-user if I do make it myself.
Thanks for your help. :)
I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.
This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard . command. Should you not like it, its page has links to alternatives.

jump over user defined text objects in vim

I am using the kana / vim-textobj-user for defining some custom user objects but the problem is I can't jump over them : case in point
let's say I am using the same indent text object which is mapped by ai and ii
I want to jump around the text in normal mode something like ]i and [i
currently I am using a very hacky way of selecting and exiting visual mode
So is there a simple way to do that and have some kind of mappings for all the other user text-objects as well .
Something like ]{text-object}
I am using the kana / vim-textobj-user for defining some custom user objects
[...]
let's say I am using the same indent text object which is mapped by ai and ii
I want to jump around the text in normal mode something like ]i and [i
Vim has a bunch of built-in commands like ]m, [M, etc. So I thought you meant ]i/[i to move the cursor to the next/previous text object. If so, vim-textobj-user supports both selecting and moving to a text object since its first release. But it's not automatic. At least you have to declare what keys (such as ]i/[i) to be used for the commands.
But I wonder about the following sesntence:
currently I am using a very hacky way of selecting and exiting visual mode
So you typed like vaio<Esc> and vai<Esc>? What you want to do is to move the cursor to the first/last line of the text object under the cursor? If so, vim-textobj-user currently doesn't provide API to define such commands.
In this case, it is probably possible to automate defining key mappings like nmap ]i vai<Esc>. But it seems to be fragile and overrides several built-in commands.
Text objects are only for applying a command (e.g. gU) or visually selecting an area of text. Motions over / to the next occurrence are highly related, but different commands. I think the vim-textobj-user plugin only provides the former, but not the latter.
My CountJump plugin is quite similar, and provides commands to set up both text objects and jumps based on regular expressions.

Resources