I'm trying to recreate some of https://github.com/tpope/vim-commentary function's in IdeaVim.
I've tried various mappings in my .ideavimrc, like for example:
nnoremap gcc :action CommentByLineComment<CR>
Which works fine but I cannot do 2gcc to comment out two lines. or ngcc to comment out n lines.
I've also tried to map them like this:
nnoremap 2gcc Vj:action CommentByLineComment<CR><Esc>
nnoremap 3gcc V2j:action CommentByLineComment<CR><Esc>
" etc...
And like this:
nnoremap gc2j V2j:action CommentByLineComment<CR><Esc>
nnoremap gc3c V3j:action CommentByLineComment<CR><Esc>
" etc...
But they don't work.
Any help on how this could be accomplished?
Ideavim update 0.52, 2019-07-23 brought support for emulation of the vim-commentary plugin.
It can be enabled by putting this line to .ideavimrc:
set commentary
It seems IdeaVim contains a number of bugs that prevent the correct execution of this kind of mapping. Feel free to create an issue here.
The functionality of commentary extension is on review right now. You can track it's status here. You can join Early Access Program to receive updates as fast as it possible.
Related
In TeX-latex-mode under Emacs (26.1) using the reftex minor mode,
When pressing C-c (, the command reftex-label (found in reftex-mode-map, from reftex-ref.el) gives pretty good suggestions of label according to context for sections (with the default value of reftex-insert-label-flags).
When pressing C-c C-s, the command LaTeX-section (found in LaTeX-mode-map, defined in latex.el) offers to enter a label for the section, with no suggestion (other than a prefix based on the level of the section, which is useful but much less than the one based on the title section offered by reftex-label).
How can one configure LaTeX-section to make the same suggestions as reftex-label for sections?
The hook LaTeX-section-hook along with the variable LaTeX-section-label would seem the right candidate for that purpose, but the documentation states that
Some LaTeX packages (such as fancyref) look at the prefix to
generate some text around cross-references automatically. When using
those packages, you should not change this variable.
for one, I assume that reftex is one of such packages, and second, I was expecting to be able to give a function inside a hook, not a list of prefixes, I wonder if I misunderstood what a hook is?
I think that one would "just" need to get LaTeX-section to abstain from offering a label and to call the function reftex-label immediately after each LaTeX-section call, but if it is not LaTeX-section-hook, I do not know which one it could be?
Before starting programming something which could involve stuff as complicated as refactoring both latex.el and reftex-ref.el, I thought I would ask in case I was missing an easier solution!!!
Visual Studio Code 1.24.1
While I was working on something today. It prompted me to do an update which I did (Update was to 1.24.1). I'm not sure if I hit a shortcut accidentally at about this same time or if this was caused by the update.
But I seem to no longer be able to use comments as a fold point.
However again, I'm not sure if I hit a shortcut of some sort, or if this was caused by the patch.
and my googlefu did not help me find an answer for visual studio code. Found many old topics about visual studio (prof not code) and for other editors. but couldn't find a topic specific to VSC.
I liked to use comments as fold points \ section headers.
Example of comments I used to use as fold points
Is this a bug in VSC 1.24.1 or did I hit a shortcut I'm unaware of?
VS Code has a method of marking the start and end of a region that can be folded and expanded easily. And also provide it a name/short description that'll always be visible.
I've tried this on Javascript code and I believe it'll work on any language in VS Code. And you can have anything in between the start and end of region - comments, few lines or code, entire functions.
In the absence of proper code folding, this is a pretty good work around that'll work for all languages on VS Code.
//#region <REGION NAME>
< You can put any type of code in here - some lines of code, functions or single or multi-line comments.
//#endregion
For python, simply omit the // in the demarcation lines, since # is a valid comment indicator:
#region <REGION NAME>
...
# any code goes here, including multiple comment lines
...
#endregion
A kind of hack I found for react is using empty tags for example
<>
{/*
Your commented code
*/}
</>
This allows you to fold the commented code between the empty tags. You can go a step further and add regions as mentioned in the other answer to add some kind of description to it
I'd like to know if it's possible to customize the auto-complete options that Adobe Brackets give when coding.
For example, in a CSS file, whenever I type "w" it gives me the some sugestions like "white-space, windows, widht".
I've never used white-space or windows... and it would be much better to remove those 2 options so that "width" (that I use a lot) would be the first.
Thanks.
If you are really annoyed by unnecessary code suggestions, then you will have to hack Brackets. Don’t worry, it’s fairly easy:
$ git clone https://github.com/adobe/brackets.git
$ cd brackets/
$ ./tools/setup_for_hacking.(bat|sh)
More info can be found at the official Brackets wiki: How to hack on Brackets.
Now you can edit the code suggestions for CSS, which are located at src/extensions/default/CSSCodeHints/CSSProperties.json. Don’t forget to reload Brackets in order to apply your changes!
I'm quite new to cc-mode and I'd like to configure it to allow me to freely format and use tabs in multiline comments. This is important to me because I want to use cog.py in my source file and need to be able to format the python source in the comment correctly. I'd be ok with comments not beeing autoindented at all, however I'd like to keep auto indenting the rest of the source code.
Example:
...
/*
[[[cog
import cog
for x in ['a','b','c']:
>cog.outl(x)
]]]
*/
...
In the line marked with > I'd like to press TAB to indent the line. cc-mode simply does nothing at all if i do so. I could use spaces there (which is inconvenient) but every (semi-)automatic re-indentation of this block would cause the spaces to vanish and therefore the python code to be incorrectly indented (which is what happens if i happen to press tab somewhere on this line after indenting it with spaces).
I tried to start emacs without my .init to be sure this is default behavior and not modified by my configuration so far. I've done google searches and read the documentation of the cc-mode variables / functions I stumbled upon (cc-mode online docs) while searching for a solution (i.e. c-indent-comments-syntactically-p, c-indent-command, c-tab-always-indent,...) but none of these seemed to solve my question.
EDIT1:
Thanks to abo-abo's idea of a "multi-major-mode" setup i've stumbled upon mmm-mode and have set up automatic switching to python mode for a cog section, which fixes most of my problems.
The only remaining problem is reindenting the whole file or a region containing a cog section. Can I somehow tell cc-mode to not change anything in comments while reindenting the file? mmm-mode + that would be a perfect solution for me.
You can use M-i to force a tab indent on the lines that you want, so you can use it to indent your comments.
You can also change your comments to use // instead. Just select your python code snippet, and do M-x comment-region:
// def foo(x):
// print 'hi'
Then the autoindent won't mess up your indentation.
Someplace I saw a snippet of code which told vi to use soft tabs and set the size of a tab. If you put this snippet at the bottom of a source file, then vi would magically use those settings for that file.
What is the syntax and rules for including that snippet in a source file? Can emacs be made to use these settings as well?
You can put this in a comment in your source file:
ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
The comment syntax depends on the type of the source file.
For C/C++/Java, this would be:
// ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
For JSP, this would be:
<%-- ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: --%>
This works if it is placed at the beginning of the source file, but I'm not sure that this'll work if placed at the end of it too.
This will not work for emacs. There might be a different way of achieving the same for emacs.
Check out :h modeline.
Example:
/* vim: ai set sw=4 ts=4 */
See :h modelines for how many lines into a file Vim will check for modeline info. The default is to check the first 5 lines.
As far as I know, vi didn't have this capability. You're likely thinking of the modeline feature of Vim. There is similar functionality in emacs, where you can put local variables in the file.
Note that, at least in Vim, modelines have had a history of vulnerabilities. This is primarily due to problematic options being specifically blacklisted instead of only allowing a certain subset of variables to be set in modelines. I'd suggest using a plugin like securemodelines.
Put this in your C++ source file:
// vim: set ft=cpp
The modeline feature looks for the string "vim:" and then executes what follows. Note: this could open up potential exploits if you don't trust the files you are opening, so think twice before enabling this feature.
Okay, first of all, in real vi you do this in the .exrc file.
Second, use
set autoindent tabstop=8 shiftwidth=4
because otherwise vi will insert tabs it thinks are only 4 characters wide. The resulting text file will not look like it makes sense in any other editor.