Jedi-vim automatically insert only matching option (need to disable it) - python

Problem is when jedi-vim finds only one match for autocomplete it automatically insert this match. I need somehow disable this feature.
What I've already tried:
let g:jedi#smart_auto_mappings = 0, but it only disables auto from ... import ... insertion;
let g:jedi#popup_on_dot = 0, but it also disable popup on dot options (so I need to type <C-space> to see it).
let g:jedi#popup_select_first = 0 also won't help as it only disable first match selection in popup menu, but not prevent auto insertion of only match.
Also I don't have any other autocomplete plugins installed. If it helps, this is my .vimrc file
Is there some way to disable auto insert of only matching feature but keep popup on dot?
P.S. you can recreate this behavior with this example:
class A(InvisibleClass):
i = 1
Then when you type A and press dot i will be inserted automatically.

This behavior is controlled by Vim's completeopt option. jedi-vim sets it to menuone,longest,preview since you haven't changed it (starting here). You should explicitly set it in your .vimrc to include noinsert.
Vim's docs say that noinsert has no effect if longest is present, but that doesn't match the behavior I'm actually seeing (NVIM 0.0.0-alpha+201510011522 (compiled Oct 5 2015 14:55:04)).

Related

PyCharm, how to skip autocomplete suggestions

I like the autocomplete feature of PyCharm in most cases. But sometimes it just suggests nonsense.
For example if I want to name a method one it renames it to __round__(self, n=None)
How can I skip the suggestion in this case? I didn't find the correct keyword in the PyCharm documentation.
If I write eg. def one I would prefer the following behaviour:
tab or/and enter --> accept suggestion
shift + ctrl + enter --> complete statement to def one(self):
Maybe you can tap space when the autocomplete suggestion appears and then delete the space instead of using Mouse.
It works for the first time pycharm shows suggestion, but if you use ctrl+space for suggstion and then tapping space, it will autocomplete default code suggestion.
Anyway, space is enough for preventing coding interruption
Go to File -> Settings -> Editor -> General -> Code Completion
UNCHECK - Insert selected suggestion by pressing space, dot, or other context-dependent keys
Now, you can use SPACE to skip.
TAB or RETURN will insert.

Using ycm in vim with python, how to retain the docstring preview while e.g. detailing parameters?

YouCompleteMe is a lovely tool for autocompletion in vim. It also shows the docstring of the 'hovered' autocomplete candidate, which is a very useful tool for me. This preview is sadly closed as soon as one confirms the candidate, e.g. by opening parentheses.
Example:
First Docstring is shown:
Typing a parenthesis will kill the docstring though:
Now i would love to keep the docstring while my 'cursor' is in the parentheses of whatever i just autocompletion for (to be detailed: obviously the docstring of the innermost parentheses, if they are nested).
Can this be done, and if yes, how?
Thank you so much in advance,
LJKS
Add below to your vimrc
let g:ycm_autoclose_preview_window_after_completion = 0
or Default.
The optional g:ycm_autoclose_preview_window_after_completion is 0 by default.
I think this will help you out:
let g:ycm_autoclose_preview_window_after_completion = 0 " default
let g:ycm_autoclose_preview_window_after_insertion = 1
ycm_autoclose_preview_window_after_insertion:
When this option is set to 1, YCM will auto-close the preview window after the user leaves insert mode. This option is irrelevant if g:ycm_autoclose_preview_window_after_completion is set or if no preview window is triggered.
Default: 0

PyDev tab alignment in inline comments

I'm sure there is an easy fix for this, but I've scoured the preferences and haven't been able to find an option with an appropriate sounding name.
Here's a simple example, the top line isn't in the code, but there to illustrate every 4th character position:
# # # # # # # #
a = 2 # something two
b = "ab" # something else foo
Between "something" and "two" I hit <tab> twice, between "something else" and "foo" I hit <tab> twice.
My expectation is that using tab inside a comment would insert the necessary spaces to get to the next tabstop (the way tab outside of a comment works) Instead, pressing tab always inserts exactly 4 spaces, regardless of the column you're currently in.
This doesn't happen in Eclipse inside a Java project, which leaves me to believe it's a PyDev thing.
Just to be clear, I expected that hitting tab twice on the first line and once in the second would produce:
# # # # # # # #
a = 2 # something two
b = "ab" # something else foo
Thanks in advance for what is almost definitely a very simple fix.
P.S. I was hesitant with tagging this with Python, if there's a user with edit privileges wants to untag it, I wouldn't be offended in the least.
This is really expected in PyDev right now.
As a note if someone would want to implement that, the related place is:
org.python.pydev.editor.autoedit.PyAutoIndentStrategy.customizeDocumentCommand -- with tests at org.python.pydev.editor.PyAutoIndentStrategyTest.
This currently enters the case where "if (!contentType.equals(ParsingUtils.PY_DEFAULT))" where we don't handle expected tab-stops as we'd on code partitions (i.e.: org.python.pydev.editor.autoedit.PyAutoIndentStrategy.handleTab).

Is is possible to customize how comments are inserted via the Keyboard Shortcut?

Is it possible to change the way PyCharm adds the hash # when using the keyboard shortcut to comment a line? (default CTRL+/)
I'd like the # to be at column 1 rather than at the indent level. Also, the cursor is moved down a line after the keyboard shortcut and I'd rather it stay on the same line.
Currently:
def foo():
my_uncommented_line
# commented_with_keyboard_shortcut
var = "and now the cursor is at the start of this line"
What I'd like:
def foo():
my_uncommented_line
# commented_with_keyboard_shortcut
var = "cursor stays on the previous line"
I'm currently searching around the JetBrains plugin repo for something that does this, but no luck thus far.
I know that this doesn't follow PEP8. I'd like to be able to make this change so that I can be consistent with the rest of the project:
Some other good reasons to ignore a particular guideline:
2. To be consistent with surrounding code that also breaks [the guideline].
The most you can do is alter the style:

How to detect if the console does support ANSI escape codes in Python?

In order to detect if console, correctly sys.stderr or sys.stdout, I was doing the following test:
if hasattr(sys.stderr, "isatty") and sys.stderr.isatty():
if platform.system()=='Windows':
# win code (ANSI not supported but there are alternatives)
else:
# use ANSI escapes
else:
# no colors, usually this is when you redirect the output to a file
Now the problem became more complex while running this Python code via an IDE (like PyCharm). Recently PyCharm added support for ANSI, but the first test fails: it has the isatty attribute but it is set to False.
I want to modify the logic so it will properly detect if the output supports ANSI coloring. One requirement is that under no circumstance I should output something out when the output is redirected to a file (for console it would be acceptable).
Update
Added more complex ANSI test script at https://gist.github.com/1316877
Django users can use django.core.management.color.supports_color function.
if supports_color():
...
The code they use is:
def supports_color():
"""
Returns True if the running system's terminal supports color, and False
otherwise.
"""
plat = sys.platform
supported_platform = plat != 'Pocket PC' and (plat != 'win32' or
'ANSICON' in os.environ)
# isatty is not always implemented, #6223.
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
return supported_platform and is_a_tty
See https://github.com/django/django/blob/master/django/core/management/color.py
I can tell you how others have solved this problem, but it's not pretty. If you look at ncurses as an example (which needs to be able to run on all kinds of different terminals), you'll see that they use a terminal capabilities database to store every kind of terminal and its capabilities. The point being, even they were never able to automatically "detect" these things.
I don't know if there's a cross-platform termcap, but it's probably worth your time to look for it. Even if it's out there though, it may not have your terminal listed and you may have to manually add it.

Categories