forked from tony/.dot-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pyvimrc
104 lines (82 loc) · 3.26 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# vim: set ft=python:
"""
Pyvim configuration. Save to file to: ~/.pyvimrc
"""
from pyvim.enums import COMMAND_BUFFER
from prompt_toolkit.enums import SEARCH_BUFFER
from prompt_toolkit.keys import Keys
from prompt_toolkit.filters import ViInsertMode, Condition, HasFocus
from prompt_toolkit.key_binding.vi_state import InputMode
from prompt_toolkit.filters.cli import ViSelectionMode
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('monokai')
# Filters for detecting insert mode (for exit_insert_mode)
vi_buffer_focussed = Condition(
lambda cli: cli.current_buffer_name.startswith('buffer-'))
in_insert_mode = ViInsertMode() & vi_buffer_focussed
in_select_mode = ViSelectionMode() & vi_buffer_focussed
# Add custom key bindings:
@editor.add_key_binding(Keys.ControlC)
def exit_mode(event):
editor.cli.vi_state.input_mode = InputMode.NAVIGATION
"""
Escape goes to vi navigation mode.
"""
buffer = event.current_buffer
vi_state = event.cli.vi_state
if vi_state.input_mode in (InputMode.INSERT, InputMode.REPLACE):
buffer.cursor_position += buffer.document.get_cursor_left_position()
if editor.cli.current_buffer_name == COMMAND_BUFFER:
editor.leave_command_mode()
vi_state.reset(InputMode.NAVIGATION)
if editor.cli.current_buffer_name == SEARCH_BUFFER:
event.cli.pop_focus()
event.cli.buffers[SEARCH_BUFFER].reset()
if bool(buffer.selection_state):
buffer.exit_selection()
@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.filename 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(['python', editor_buffer.filename])
six.moves.input('Press enter to continue...')
editor.cli.run_in_terminal(execute)