How to break lines "inplace" with Atom Editor - python-3.x

When I'm typing a long line and press Enter in Atom Editor, I get the following:
I would like to know to set it so when I press Enter (or something equivalent) I get something with the following flavor:
Thanks a lot in advance!!

I suggest you install an indentation package for Atom.
Try the python-indent package.
It automatically applies the PEP8 style guide for indentation when you enter a newline.
It also works when splitting method calls with many args same as your example.
Just make sure to configure the pre-included language-python package first to use "soft" tabs.
(Settings > Packages > language-python)

Related

Sublime Text Editor snippet to remove parentheses

Sublime is able to add parentheses, brackets (curly and square), apostrophes, and quotes to highlighted text by default. I've tried but can't seem to find a way to have it remove those as well. What I'd like to be able to do is highlight some text that is surrounded by parentheses and have it remove those. Is there a good way to do that using snippets?
I suspect it can be done with use of allFollowingCharacter and allPrecedingCharacter but it seems those might be from a previous version of Sublime when those were in XML instead of the current JSON...?
Any help would be appreciated!
With surround you can do this. Install it via Package Control. (Package Control Installation)
Open the command palette:
CTRLSHIFTP on Linux and Windows,
CMDSHIFTP on Mac.
Search for Surround: delete surround and type in ( and Enter and you are done!
I'm surprised this question isn't searched more regularly!
BracketHighlighter is an excellent utility that includes convenient deleting of parenthesis. To cut to the chase, install BracketHighlighter and set bh_remove_brackets to whatever shortcut you'd like to be able to delete parentheses. Search up bh_remove_brackets in the example sublime keymap to see an example!

How can I use Linux command 'cd' when I have Greek language pack?

Sometimes I encounter this problem. In Greek, desktop is called 'Επιφάνεια εργασίας'. I can switch to Greek on the terminal, but I can't use intonation, or however the mark above α is called. Is there any way to use ά instead of α? Thank you in advance.
Tip: the problem is that, to put intonation, you press first the ' key and then the letter. But when I do this, I get: "Επιφ'ανεια εργασ'ιας".

ES6 backtick support in Sublime Text 3

In my Sublime Text 3 (build 3065), ES6 string interpolation backticks seem to confuse the syntax highlighting in html files. For example
console.log(`"`)
would lead the syntax highlighting to assume we have an unmatched quote here, rather than figuring this is a single quotation mark quoted by backticks - which renders the remainder of the source file useless in terms of code highlighting.
Has this been solved in an updated build or add-on?
Meanwhile I can workaround it by closing the imaginary quotation in a comment.
console.log(`"`) // "
You will need to install a separate package for syntax highlighting in Sublime. There is currently a TextMate/Sublime 2 package for this (which should work for Sublime 3) here: https://github.com/Benvie/JavaScriptNext.tmLanguage
From the Installation and Use heading:
If you haven't already, install Package Control, then select
JavaScript Next from the Package Control: Install Package dropdown
list in the Command Palette.
To set this as your default JavaScript syntax, open a javascript file,
then select View -> Syntax -> Open all with current extension as... ->
JavascriptNext.
You may also need to change the ColorScheme. Pick one from Preferences
-> Color Scheme -> JavaScriptNext.
EDIT: Original Answerer posted a more widely used highlighter in comment below. It is here:
github.com/babel/babel-sublime

Stop highlighted text from autofilling sublime's goto anything search

I use goto anything quite a bit, but mainly for searching for files. It goes a little something like this:
cmd p, immediately start typing file name
shit, there's a random string of junk at the beginning of my search
backspace, backspace, backsp....
type file name
receive list of file choices that I wanted to begin with
Is there a setting I can set somewhere to make the behavior a little more sane for my use-case?
Thanks.
I don't believe that's a default behavior. What plugins do you have installed? If you log the commands (sublime.log_commands(True) in the ST console), what do you see? I get command: show_overlay {"overlay": "goto", "show_files": true}. If it's not that, a plugin may be binding to super + p. If that's the case, you may either remove the plugin, or create a user key binding with the proper command/arguments.

Is it possible to format C++ code with VIM?

I am rather new to VIM. I got some source code and this is a mess. At a first sight I would like at least to get a clear and organised view of the code, so I like to get it rightly formatted, I mean indented depending on the depth of the functions and so.
I wonder if it can be done with VIM, and otherwise which other commandline tools for that can you recommend.
Thanks
While vim is a true Swiss-knife I still prefer external tools for some jobs. This approach is some times much more intuitive and easy to remember than using the built-in equivalent.
In the case of indenting, I filter the whole file buffer through astyle. The astyle parameters are much easier to grasp in a couple of minutes, especially if you are not a vim guru. Also astyle provides much more flexibility in fine-tuning the output.
First install astyle:# apt-get install astyle
Then inside vim:
:%!astyle (simple case - astyle default mode is C/C++)
or
:%!astyle --mode=c --style=ansi -s2 (ansi C++ style, use two spaces per indent level)
or
:1,40!astyle --mode=c --style=ansi (ansi C++ style, filter only lines 1-40)
you can do the following:
gg=G
I would highly recommend clang-format nowadays. It allows simple integration of clang-format into Vim, once you have clang-format installed:
http://clang.llvm.org/docs/ClangFormat.html#vim-integration
It is the only code beautifier that really understands your C++ code, and it is really intelligent to beautify the code more like a human being than a machine. E.g.:
void TestFunction(int argument1, int argument2,
int argument3);
void TestFunctionVeryLongName(int argument1,
int argument2,
int argument3);
void TestFunctionWithRidiculouslyLongName(
int argument1, int argument2, int argument3);
Vim will definitely do this, although the results may not be perfect:
First, select the entire file in visual mode: ggVG
Then hit = to reindent everything.
You can learn more about the equal command with: :help =
There is also a Vim plugin relying on clang-format: vim-clang-format
Then you can simply map the formatting command to whatever suits you.
There is a vim plugin that enables formatting on your code from within vim. It's called vim-autoformat and you can download it here:
https://github.com/vim-autoformat/vim-autoformat
It integrates external code-formatting programs into vim. For example, if you want to format C, C++, C# or Java code, you need to install the program astyle, and vim sets it as the format program automatically.
I don't write C++ code, but I write some Java code.
Instead, Vim supports the formatting of some common languages.
I have set up a short cut for me to format the whole code in the buffer.
It will return to the line I just edited :)
" format the file
map <leader>fm gg=G'.
A generic solution along the lines of m000's idea is to use UniversalIndentGUI as an external tool.
Just had to solve this exact problem, so I thought I'd contribute to save others some time.
You can use gg=G to indent your code. But things get hard to understand the moment you want to tweak how that auto-indenting happens. Therefore, if you only care that errant whitespace is removed and don't really care about formatting style, gg=G is the quickest way to go about it, because its built-in.
If you do want to control the style (for example, you're trying to make your code conform to a style guide), then you're going to need an external tool to process your file. You can invoke that tool from within vim with: :%!<toolname> <options>. This pipes the file through the tool and re-loads the processed result. (You can obviously use this for anything else you want to do to your file too)
So the next question is, what external tool should you choose? Regardless, the method is the same:
Install the tool of choice
Make sure its in your path
Add a line to your vimrc file that creates a shortcut key to use so you save time
Use it.
Now, which tool you use depends on the style you're trying to replicate. If you're trying to replicate a widely used style, then chances are astyle is all you need.
If you're trying to replicate a custom style, then you will need two things:
UniversalIndentGui - a front end that lets you play around with various options and live-preview their effect on the source file
A set of source code formatting tools installed and in your path
Between uncrustify and greatcode, you should be able to completely replicate the style you want.
Actually, I lied. There is another way and its called clang-format. However, you're going to want to read the documentation on it and its still in early stages so some options don't work very well. It is a beautiful tool though (definitely the smartest of the lot because constructs an AST of your code) and it is even available for Windows.
If you're going to take the time to read the manual, you also want to check out GNU Indent.
Of course, there is the last way, which is actually taking the time to learn vim's indent rules and writing one for your style. It will take time, but it will work with gg=G.
Some notes on astyle vs uncrustify vs greatcode:
Astyle is good for general formatting, but can't do things like align the declaration of variables and re-style comments very well.
Uncrustify can do a LOT of stuff that astyle can't, but be prepared to spend an hour playing around until you've found the correct combination of options you need. (Or if you feel like wasting a lot of time, use genetic algorithms to figure out the best combination of options for your style and when you do share the code and give me a link so I can use it too :) )
Note that you don't have to choose one tool. With vim, you can map one keystroke to execute several commands in succession, so theoretically you could use a combination of these tools to get exactly what you're looking for.
Last but not least, here's an excerpt from my .vimrc file, where I have mapped F12 to invoke astyle with some options:
"A2 = attached brackets
"-s8 indent 8 spaces
"-xc attached braces to class declarations
"-xj remove braces for single statement ifs and elses
"-c convert tabs to spaces in the non-indentation part of the line
map <F12> :%!astyle -A2 -s8 -xc -xj -c<CR>
Don't judge me on the style. Just use the tool to reproduce what you want.

Resources