3
3
" Maintainer: skywind3000 (at) gmail.com, 2016, 2017, 2018, 2019, 2020
4
4
" Homepage: http://www.vim.org/scripts/script.php?script_id=5431
5
5
"
6
- " Last Modified: 2020/02/05 06:36
6
+ " Last Modified: 2020/02/06 14:43
7
7
"
8
8
" Run shell command in background and output to quickfix:
9
9
" :AsyncRun[!] [options] {cmd} ...
44
44
" $VIM_COLUMNS - How many columns in vim's screen
45
45
" $VIM_LINES - How many lines in vim's screen
46
46
"
47
- " parameters also accept these environment variables wrapped by
48
- " "$(...)", and "$(VIM_FILEDIR)" will be expanded as file directory
47
+ " Parameters also accept these environment variables wrapped by
48
+ " "$(...)", and "$(VIM_FILEDIR)" will be expanded as file directory.
49
+ "
50
+ " It is safe to use "$(...)" than "%:xx" when filenames contain spaces.
49
51
"
50
52
" There can be some options before [cmd]:
51
53
" -mode=0/1/2 - start mode: 0(async, default), 1(makeprg), 2(!)
83
85
"
84
86
" Requirements:
85
87
" vim 7.4.1829 is minimal version to support async mode
88
+ " vim 8.1.1 is minial version to use "-mode=term"
86
89
"
87
90
" Examples:
88
91
" :AsyncRun gcc % -o %<
89
92
" :AsyncRun make
90
- " :AsyncRun -raw python $(VIM_FILEPATH)
93
+ " :AsyncRun -raw -cwd=$(VIM_FILEDIR) python " $(VIM_FILEPATH)"
91
94
" :AsyncRun -cwd=<root> make
92
- " :AsyncRun! grep -R <cword> .
95
+ " :AsyncRun! grep -n - R <cword> .
93
96
" :noremap <F7> :AsyncRun gcc % -o %< <cr>
94
97
"
98
+ " Run in the internal terminal:
99
+ " :AsyncRun -mode=term bash
100
+ " :AsyncRun -mode=term -pos=tab bash
101
+ " :AsyncRun -mode=term -pos=curwin bash
102
+ " :AsyncRun -mode=term -pos=top -rows=15 bash
103
+ " :AsyncRun -mode=term -pos=bottom -rows=15 bash
104
+ " :AsyncRun -mode=term -pos=left -cols=40 bash
105
+ " :AsyncRun -mode=term -pos=right -cols=40 bash
106
+ "
95
107
" Additional:
96
108
" AsyncRun uses quickfix window to show job outputs, in order to
97
109
" see the outputs in realtime, you need open quickfix window at
@@ -1061,6 +1073,7 @@ endfunc
1061
1073
function ! s: start_in_terminal (opts)
1062
1074
let command = a: opts .command
1063
1075
let pos = get (a: opts , ' pos' , ' bottom' )
1076
+ let hidden = get (a: opts , ' hidden' , 0 )
1064
1077
if has (' patch-8.1.1' ) == 0 && has (' nvim-0.3' ) == 0
1065
1078
call s: ErrorMsg (" Terminal is not available in this vim" )
1066
1079
return -1
@@ -1083,47 +1096,50 @@ function! s:start_in_terminal(opts)
1083
1096
endif
1084
1097
endfor
1085
1098
if pos == ' tab'
1099
+ exec " tab split"
1086
1100
if has (' nvim' ) == 0
1087
- let cmd = ' tab term ++noclose ++norestore'
1101
+ let cmd = ' tab term ++noclose ++norestore ++curwin '
1088
1102
if has (' patch-8.1.2255' ) || v: version >= 802
1089
- exec cmd . ' ++shell ' . command
1103
+ exec cmd . ' ++shell ++kill=term ' . command
1090
1104
else
1091
- exec cmd . ' ' . command
1092
- endif
1093
- if &bt == ' terminal'
1094
- setlocal nonumber signcolumn = no norelativenumber
1105
+ exec cmd . ' ++kill=term ' . command
1095
1106
endif
1096
1107
else
1097
- exec ' tabe term://' . fnameescape (command )
1098
- if &bt == ' terminal'
1099
- setlocal nonumber signcolumn = no norelativenumber
1100
- startinsert
1108
+ exec ' term ' . command
1109
+ endif
1110
+ if &bt == ' terminal'
1111
+ setlocal nonumber signcolumn = no norelativenumber
1112
+ let b: asyncrun_cmd = command
1113
+ exec has (' nvim' )? ' startinsert' : ' '
1114
+ if has_key (a: opts , ' hidden' )
1115
+ exec ' setlocal bufhidden=' .. (hidden ? ' hide' : ' ' )
1101
1116
endif
1102
1117
endif
1103
1118
return 0
1104
1119
elseif pos == ' cur' || pos == ' curwin' || pos == ' current'
1105
1120
if has (' nvim' ) == 0
1106
1121
let cmd = ' term ++noclose ++norestore ++curwin'
1107
1122
if has (' patch-8.1.2255' ) || v: version >= 802
1108
- exec cmd . ' ++shell ' . command
1123
+ exec cmd . ' ++shell ++kill=term ' . command
1109
1124
else
1110
- exec cmd . ' ' . command
1111
- endif
1112
- if &bt == ' terminal'
1113
- setlocal nonumber signcolumn = no norelativenumber
1125
+ exec cmd . ' ++kill=term ' . command
1114
1126
endif
1115
1127
else
1116
1128
exec ' term ' . command
1117
- if &bt == ' terminal'
1118
- setlocal nonumber signcolumn = no norelativenumber
1119
- startinsert
1129
+ endif
1130
+ if &bt == ' terminal'
1131
+ setlocal nonumber signcolumn = no norelativenumber
1132
+ let b: asyncrun_cmd = command
1133
+ exec has (' nvim' )? ' startinsert' : ' '
1134
+ if has_key (a: opts , ' hidden' )
1135
+ exec ' setlocal bufhidden=' .. (hidden ? ' hide' : ' ' )
1120
1136
endif
1121
1137
endif
1122
1138
return 0
1123
1139
endif
1124
1140
let uid = win_getid ()
1125
- noautocmd windo call s: save_restore_view (0 )
1126
- noautocmd call win_gotoid (uid)
1141
+ keepalt noautocmd windo call s: save_restore_view (0 )
1142
+ keepalt noautocmd call win_gotoid (uid)
1127
1143
let focus = get (a: opts , ' focus' , 1 )
1128
1144
let origin = win_getid ()
1129
1145
if avail < 0
@@ -1145,7 +1161,9 @@ function! s:start_in_terminal(opts)
1145
1161
exec " normal! " . avail . " \<c-w>\<c-w> "
1146
1162
endif
1147
1163
let uid = win_getid ()
1148
- noautocmd windo call s: save_restore_view (1 )
1164
+ keepalt noautocmd call win_gotoid (origin)
1165
+ keepalt noautocmd windo call s: save_restore_view (1 )
1166
+ keepalt noautocmd call win_gotoid (origin)
1149
1167
noautocmd call win_gotoid (uid)
1150
1168
if has (' nvim' ) == 0
1151
1169
let cmd = ' term ++noclose ++norestore ++curwin '
@@ -1154,14 +1172,15 @@ function! s:start_in_terminal(opts)
1154
1172
else
1155
1173
exec cmd . ' ++kill=term ' . command
1156
1174
endif
1157
- if &bt == ' terminal'
1158
- setlocal nonumber signcolumn = no norelativenumber
1159
- endif
1160
1175
else
1161
1176
exec ' term ' . command
1162
- if &bt == ' terminal'
1163
- setlocal nonumber signcolumn = no norelativenumber
1164
- startinsert
1177
+ endif
1178
+ if &bt == ' terminal'
1179
+ setlocal nonumber signcolumn = no norelativenumber
1180
+ let b: asyncrun_cmd = command
1181
+ exec has (' nvim' )? ' startinsert' : ' '
1182
+ if has_key (a: opts , ' hidden' )
1183
+ exec ' setlocal bufhidden=' .. (hidden ? ' hide' : ' ' )
1165
1184
endif
1166
1185
endif
1167
1186
if focus == 0 && &bt == ' terminal'
@@ -1570,7 +1589,7 @@ endfunc
1570
1589
" asyncrun -version
1571
1590
" ----------------------------------------------------------------------
1572
1591
function ! asyncrun#version ()
1573
- return ' 2.2.5 '
1592
+ return ' 2.2.6 '
1574
1593
endfunc
1575
1594
1576
1595
@@ -1605,27 +1624,27 @@ function! asyncrun#quickfix_toggle(size, ...)
1605
1624
endfunc
1606
1625
let s: quickfix_open = 0
1607
1626
let l: winnr = winnr ()
1608
- noautocmd windo call s: WindowCheck (0 )
1609
- noautocmd silent ! exec ' ' .l: winnr .' wincmd w'
1627
+ keepalt noautocmd windo call s: WindowCheck (0 )
1628
+ keepalt noautocmd silent ! exec ' ' .l: winnr .' wincmd w'
1610
1629
if l: mode == 0
1611
1630
if s: quickfix_open != 0
1612
1631
silent ! cclose
1613
1632
endif
1614
1633
elseif l: mode == 1
1615
1634
if s: quickfix_open == 0
1616
- exec ' botright copen ' . ((a: size > 0 )? a: size : ' ' )
1617
- wincmd k
1635
+ keepalt exec ' botright copen ' . ((a: size > 0 )? a: size : ' ' )
1636
+ keepalt wincmd k
1618
1637
endif
1619
1638
elseif l: mode == 2
1620
1639
if s: quickfix_open == 0
1621
- exec ' botright copen ' . ((a: size > 0 )? a: size : ' ' )
1622
- wincmd k
1640
+ keepalt exec ' botright copen ' . ((a: size > 0 )? a: size : ' ' )
1641
+ keepalt wincmd k
1623
1642
else
1624
1643
silent ! cclose
1625
1644
endif
1626
1645
endif
1627
- noautocmd windo call s: WindowCheck (1 )
1628
- noautocmd silent ! exec ' ' .l: winnr .' wincmd w'
1646
+ keepalt noautocmd windo call s: WindowCheck (1 )
1647
+ keepalt noautocmd silent ! exec ' ' .l: winnr .' wincmd w'
1629
1648
endfunc
1630
1649
1631
1650
0 commit comments