Skip to content

Commit 5df7cb3

Browse files
author
jgors
committed
update to str formatting
1 parent 2beaefd commit 5df7cb3

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Key mappings
4646
`map <Leader>vip :call VimuxIpy()<CR>`
4747

4848
* Optionally, an argument can be passed into `VimuxIpy()` to start ipython
49-
in a preferred way: eg. `"ipython --pylab"`, or `"ipython --profile=some_cool_profile"`. If
50-
no argument is passed to `VimuxIpy()`, then normal ipython will start without any flags set.
49+
in a preferred way: eg. `VimuxIpy("ipython --pylab")`, or `VimuxIpy("ipython --profile=some_cool_profile")`.
50+
If no argument is passed to `VimuxIpy()`, then normal ipython will start without any flags set.
5151

5252
After the iPython tmux split is created, these keybindings are made:
5353

ftplugin/python/ipy.vim

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ python << endpython
77
import vim
88
import re
99

10+
reg_to_use = 'z'#'+'
1011

1112
def run_visual_code():
1213
"""
@@ -36,7 +37,7 @@ def run_visual_code():
3637
lines += "\n"
3738

3839
# register might need to be set as * instead of +
39-
vim.command(":let @*='%s'" % (lines.replace("'", "''")))
40+
vim.command(":let @{0}='{1}'".format(reg_to_use, lines.replace("'", "''")))
4041
vim.command(':call VimuxRunCommand("%paste\n", 0)')
4142

4243
elif use_cpaste:
@@ -61,7 +62,7 @@ def run_visual_code():
6162
# Shift the whole text by nindent spaces (so the first line has 0 indent)
6263
if nindent > 0:
6364
pat = '\s' * nindent
64-
lines = "\n".join([re.sub('^%s' % pat, '', l) for l in lines])
65+
lines = "\n".join([re.sub('^{0}'.format(pat), '', l) for l in lines])
6566
#print '-----------------'
6667
#print lines
6768
else:
@@ -72,15 +73,15 @@ def run_visual_code():
7273
lines += "\n"
7374

7475
vim.command(':call VimuxRunCommand("%cpaste\n", 0)')
75-
vim.command(':call VimuxRunCommand("%s", 0)' % lines)
76+
vim.command(':call VimuxRunCommand("{0}", 0)'.format(lines))
7677
vim.command(':call VimuxRunCommand("\n--\n", 0)')
7778

7879
elif use_raw:
7980
# NOTE doesn't work well
8081
lines = "\n".join(lines)
8182
lines += "\n"
82-
vim.command("let @+='%s'" % (lines.replace("'", "''")))
83-
vim.command(':call VimuxSendText(@+)')
83+
vim.command("let @{0}='{1}'".format(reg_to_use, lines.replace("'", "''")))
84+
vim.command(':call VimuxSendText(@{0})'.format(reg_to_use))
8485

8586
elif use_register_with_cpaste:
8687
# works
@@ -96,16 +97,16 @@ def run_visual_code():
9697
# Shift the whole text by nindent spaces (so the first line has 0 indent)
9798
if nindent > 0:
9899
pat = '\s' * nindent
99-
lines = "\n".join([re.sub('^%s' % pat, '', l) for l in lines])
100+
lines = "\n".join([re.sub('^{0}'.format(pat), '', l) for l in lines])
100101
else:
101102
lines = "\n".join(lines)
102103

103104

104105
# Add empty newline at the end
105106
lines += "\n"
106-
vim.command("let @+='%s'" % (lines.replace("'", "''"))) #doesn't work w/o this
107+
vim.command("let @{0}='{1}'".format(reg_to_use, lines.replace("'", "''"))) #doesn't work w/o this
107108
vim.command(':call VimuxRunCommand("%cpaste\n", 0)')
108-
vim.command(':call VimuxSendText(@+)')
109+
vim.command(':call VimuxSendText(@{0})'.format(reg_to_use))
109110
vim.command(':call VimuxRunCommand("\n--\n", 0)')
110111

111112
# Move cursor to the end of the selection
@@ -120,27 +121,27 @@ def run_cell(save_position=False, cell_delim='####'):
120121

121122
The cell_delim arg can be set such that it is the same as what the
122123
iPython notebook uses to delimit its code cells (cell_delim='# <codecell>')
123-
Thus, if cells are seperated with this, then the script can be uploaded &
124-
opened as an iPython notebook, and the iPython NB environment will
125-
recognize the delimited cell blocks. NOTE, in order for this to work,
124+
Thus, if cells are seperated with this, then the script can be opened
125+
as an iPython notebook and the iPython NB environment will recognize
126+
the delimited cell blocks. NOTE, in order for this to work,
126127
the first thing at the top of the script needs to be:
127128
# <nbformat>3</nbformat>
128129

129130
(http://ipython.org/ipython-doc/stable/interactive/htmlnotebook.html#the-notebook-format)
130131

131-
The :?%s?;/%s/ part creates a range by:
132-
?%s? searches backwards for the cell_delim,
132+
The :?{0}?;/{0}/ part creates a range by:
133+
?{0}? searches backwards for the cell_delim,
133134
then the ';' starts the range from the result of the
134135
previous search (cell_delim) to the end of the
135-
range at /%s/ (the next cell_delim).
136+
range at /{0}/ (the next cell_delim).
136137
"""
137138

138139
if save_position:
139140
# Save cursor position
140141
(row, col) = vim.current.window.cursor
141142

142143
# Run chunk on cell range
143-
vim.command(':?%s?;/%s/ :python run_visual_code()' % (cell_delim, cell_delim))
144+
vim.command(':?{0}?;/{0}/ :python run_visual_code()'.format(cell_delim))
144145

145146
# this clears the highlighting from the delim search
146147
vim.command(':noh')
@@ -173,6 +174,10 @@ function! VimuxIpy(...)
173174
" Interrupt any command running in the runner pane
174175
map <Leader>vq :VimuxInterruptRunner<CR>
175176
177+
" Zoom the tmux runner page
178+
" also, need to use tmux bind-key + z to restore the runner pane.
179+
"map <Leader>vz :VimuxZoomRunner<CR>
180+
176181
" Change pane height
177182
let g:VimuxHeight = "35"
178183

0 commit comments

Comments
 (0)