File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 18
18
- [ Aesthetics] ( #aesthetics )
19
19
- [ Remaps] ( #remaps )
20
20
- [ General] ( #general )
21
+ - [ Floating terminal] ( #floating-terminal )
21
22
- [ Split navigation] ( #split-navigation )
22
23
- [ Set - Unset] ( #set-unset )
23
24
- [ LSP] ( #lsp )
@@ -124,6 +125,14 @@ nvim/
124
125
| ` <leader>s ` | Source file in current buffer |
125
126
126
127
128
+ ### Floating terminal <a name =" floating-terminal " ></a > ###
129
+
130
+ ***
131
+ | Keybind | Action |
132
+ | ---------------| ----------------------------|
133
+ | ` <leader>t ` | Toggle floating terminal |
134
+
135
+
127
136
### Split navigation <a name =" split-navigation " ></a > ###
128
137
***
129
138
| Keybind | Action |
Original file line number Diff line number Diff line change
1
+ vim .keymap .set (" n" , " <leader>t" , " <cmd>FloatingTerminal<cr>" )
2
+ vim .keymap .set (" t" , " <leader>t" , " <cmd>FloatingTerminal<cr>" )
3
+
Original file line number Diff line number Diff line change
1
+ local state = {
2
+ floating = {
3
+ buf = - 1 ,
4
+ win = - 1 ,
5
+ }
6
+ }
7
+
8
+ local function create_floating_window (opts )
9
+ opts = opts or {}
10
+
11
+ local width = opts .width or math.floor (vim .o .columns * 0.8 )
12
+ local height = opts .height or math.floor (vim .o .lines * 0.8 )
13
+
14
+ local col = math.floor ((vim .o .columns - width ) / 2 )
15
+ local row = math.floor ((vim .o .lines - height ) / 2 )
16
+
17
+ local buf = nil
18
+ if vim .api .nvim_buf_is_valid (opts .buf ) then
19
+ buf = opts .buf
20
+ else
21
+ buf = vim .api .nvim_create_buf (false , true )
22
+ end
23
+
24
+ local win_config = {
25
+ relative = " editor" ,
26
+ width = width ,
27
+ height = height ,
28
+ col = col ,
29
+ row = row ,
30
+ style = " minimal" ,
31
+ border = " rounded" ,
32
+ }
33
+
34
+ local win = vim .api .nvim_open_win (buf , true , win_config )
35
+
36
+ return { buf = buf , win = win }
37
+ end
38
+
39
+ local toggle_terminal = function ()
40
+ if not vim .api .nvim_win_is_valid (state .floating .win ) then
41
+ state .floating = create_floating_window { buf = state .floating .buf }
42
+ if vim .bo [state .floating .buf ].buftype ~= " terminal" then
43
+ vim .cmd .terminal ()
44
+ end
45
+ else
46
+ vim .api .nvim_win_hide (state .floating .win )
47
+ end
48
+ end
49
+
50
+ vim .api .nvim_create_user_command (" FloatingTerminal" , toggle_terminal , {})
You can’t perform that action at this time.
0 commit comments