-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython.vimrc
186 lines (159 loc) · 4.78 KB
/
python.vimrc
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"python config
" g:pythonthreedll, g:pythonthreehome & g:python3_host_prog are set in init.vim
let g:CodeFence = "###"
function! IsLineIndented()
let lineContent = getline('.')
if match(lineContent, ' ') == 0
return 1
else
return 0
endif
endfunction
function! IsFence()
return getline('.') == g:CodeFence
endfunction!
function! BuildFence()
exe "normal Go".g:CodeFence
if IsLineIndented()
normal 0dt#
endif
endfunction
function! OpenCell() abort
let cmd = 'normal *kV``jo'
execute cmd
endfunction
function! CloseCell() abort
let cmd = 'normal #jV``'
execute cmd
normal -
endfunction
function! BetweenCell() abort
let Start = line(".")
let End = search('^'.g:CodeFence, 'Wbs')
normal +
if Start - End == 1
normal V
else
normal V''
endif
endfunction
function! JumpCell() abort
if search('^'.g:CodeFence, 'W') == 0
norm G
endif
endfunction
function! JumpCellBack() abort
if search('^'.g:CodeFence, 'Wb') == 0
norm gg
endif
endfunction
function! SelectVisual() abort
if search('^'.g:CodeFence, 'W') == 0
call BuildFence()
call CloseCell()
else
normal -
call BetweenCell()
endif
endfunction
function! SendCell() abort
call SelectVisual()
endfunction
function DebugCell()
call SelectVisual()
normal >O
normal Idef DebugCell():
normal `>o
normal IDebugCell()
endfunction
function DebugDelete()
if search("def DebugCell", "w") == 0
echo "Debug Cell is not found!"
else
call SelectVisual()
normal <
normal '<dd
normal `>dd
endif
endfunction
"function RedrawiPython()
" let l:current_window = win_getid()
" "echo current_window
" let wins = win_findbuf(bufnr('ipython.EXE'))
" "echo wins
" call win_gotoid(wins[0])
" norm i
" norm <c-l>
"endfunction
augroup PythonRepl
autocmd!
" code snippet
autocmd Filetype python inoremap <buffer> ;f ###<CR><Esc>
autocmd Filetype python inoremap <buffer> ;cb .to_clipboard()
autocmd Filetype python inoremap <buffer> ;ct .copy(True)
autocmd Filetype python inoremap <buffer> ;it inplace=True
autocmd Filetype python inoremap <buffer> ;fr .iloc[0].T
autocmd Filetype python inoremap <buffer> ;lr .iloc[-1].T
"autocmd Filetype python inoremap <buffer> ;db __import__("IPython").core.debugger.set_trace()
" REPL actions
"autocmd Filetype python nmap <buffer> <localleader><localleader> :call SendCell()<cr><cr>
" TODO to activate terminal and jump back using
" local current_window = vim.api.nvim_get_current_win() -- save current window
" vim.api.nvim_set_current_win(current_window)
autocmd Filetype python nnoremap <buffer> <localleader>l <c-w><c-l>i<c-l><Cmd>wincmd h<CR>
autocmd Filetype python nnoremap <buffer> <localleader>v <cmd>call SelectVisual()<cr>
autocmd Filetype python nnoremap <buffer> <localleader>db <cmd>call DebugCell()<cr>
autocmd Filetype python nnoremap <buffer> <localleader>dd <cmd>call DebugDelete()<cr>:'<,'>g/core.debugger.set_trace/d<cr>
" autocmd Filetype python nnoremap <buffer> <localleader><localleader> <cmd>call JumpCell()<cr>
augroup END
tnoremap ;cb .to_clipboard()
tnoremap ;fr .iloc[0].T
tnoremap ;lr .iloc[-1].T
" diagnostic box open by cursor
"autocmd CursorHold * lua vim.diagnostic.open_float()
function! MyTabLine()
let s = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let s .= '%' . i . 'T'
let s .= (i == t ? '%1*' : '%2*')
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
let s .= ' ' . i . ' '
let bufnr = buflist[winnr - 1]
let file = bufname(bufnr)
let buftype = getbufvar(bufnr, '&buftype')
if buftype == 'help'
let file = 'help:' . fnamemodify(file, ':t:r')
elseif buftype == 'quickfix'
let file = 'quickfix'
elseif buftype == 'nofile'
if file =~ '\/.'
let file = substitute(file, '.*\/\ze.', '', '')
endif
else
let file = pathshorten(fnamemodify(file, ':p:~:.'))
if getbufvar(bufnr, '&modified')
let file = '+' . file
endif
endif
if file == ''
let file = '[No Name]'
endif
let s .= ' ' . file
if i < tabpagenr('$')
let s .= ' %#TabLine#|'
else
let s .= ' '
endif
let i = i + 1
endwhile
let s .='%#TabLineSel#'
let s .="%{%v:lua.require'nvim-navic'.get_location()%}"
let s .= '%T%#TabLineFill#%='
let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
return s
endfunction
set tabline=%!MyTabLine()