-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathpyvimrc
81 lines (63 loc) · 2.32 KB
/
pyvimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# vim: set ft=python:
"""
Pyvim configuration. Save to file to: ~/.pyvimrc
"""
from prompt_toolkit.application import run_in_terminal
from prompt_toolkit.filters import ViInsertMode
from prompt_toolkit.key_binding.key_processor import KeyPress
from prompt_toolkit.keys import Keys
from subprocess import call
import six
__all__ = (
'configure',
)
def configure(editor):
"""
Configuration function. We receive a ``pyvim.editor.Editor`` instance as
argument that we can manipulate in here.
"""
# Show line numbers by default. (:set number)
editor.show_line_numbers = True
# Highlight search. (:set hlsearch)
editor.highlight_search = True
# Case insensitive searching. (:set ignorecase)
editor.ignore_case = True
# Expand tab. (Pressing Tab will insert spaces.)
editor.expand_tab = True # (:set expandtab)
editor.tabstop = 4 # (:set tabstop=4)
# Scroll offset (:set scrolloff)
editor.scroll_offset = 2
# Show tabs and trailing whitespace. (:set list)
editor.display_unprintable_characters = True
# Use Jedi for autocompletion of Python files. (:set jedi)
editor.enable_jedi = True
# Apply colorscheme. (:colorscheme emacs)
editor.use_colorscheme('emacs')
# Add custom key bindings:
@editor.add_key_binding('j', 'j', filter=ViInsertMode())
def _(event):
"""
Typing 'jj' in Insert mode, should go back to navigation mode.
(imap jj <esc>)
"""
event.cli.key_processor.feed(KeyPress(Keys.Escape))
@editor.add_key_binding(Keys.F9)
def save_and_execute_python_file(event):
"""
F9: Execute the current Python file.
"""
# Save buffer first.
editor_buffer = editor.current_editor_buffer
if editor_buffer is not None:
if editor_buffer.location is None:
editor.show_message("File doesn't have a filename. Please save first.")
return
else:
editor_buffer.write()
# Now run the Python interpreter. But use
# `CommandLineInterface.run_in_terminal` to go to the background and
# not destroy the window layout.
def execute():
call(['python3', editor_buffer.location])
six.moves.input('Press enter to continue...')
run_in_terminal(execute)