Skip to content

Commit aa10f2b

Browse files
authored
Merge pull request #18 from michaelb/dev
Dev
2 parents 22d199d + 9eb11c0 commit aa10f2b

File tree

6 files changed

+100
-13
lines changed

6 files changed

+100
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmp_config

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ To display a tip (and not a quote) in your vim-startify you can include the foll
3535

3636
You'll probably also want to deactivate the basic tip display at startup.
3737

38-
## Add your own tips
39-
40-
If you want, you can add your own tips by modifying the files in the tips folder.
41-
You may find them on your own system (probably in your plugin manager's files), but to simplify that I suggest forking my repo and adding your own changes in a version controlled repo.
42-
43-
Tips must not exceed 70 characters
4438

4539
## Important note
4640

convert_file_to_vim_list.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
3+
if len(sys.argv) != 2:
4+
print("This script requires an argument corresponding to the file path to listify")
5+
6+
filepath = sys.argv[1]
7+
8+
with open(filepath, 'r') as f:
9+
print("[", end="")
10+
for line in f.readlines():
11+
print("\"" + line.strip("\n") + "\",", end="")
12+
print("]")

plugin/tips/miscallenous.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ gt : show next tab
77
C-w : (in insert mode) erases word from start to position
88
C-u : (in insert mode) erases line from start to position
99
// : run your previous search
10-
CTRL + w + x : exchange with next window
10+
C-w-x : exchange with next window
11+
set <option> ? : see the value of a config option

plugin/tips/othermodes.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
C-k (+characters) : insert digraphs (æ,π...) in insert mode
2+
C-K * p : insert π (in insert mode)
3+
C-K Eu : insert € (in insert mode)
4+
C-K +- : insert ± (in insert mode)
5+
C-K OK : insert ✓ (in insert mode)
6+
C-K XX : insert ✗ (in insert mode)
7+
C-K AN : insert ∧ ('and' symbol) (in insert mode)
8+
C-K OR : insert ∨ ('or' symbol) (in insert mode)
9+
C-K (- : insert ∈ (in insert mode)
10+
C-a : insert the last content inserted (in insert mode)
11+
C-@ : insert the last content insert and quit insert mode (in insert mode)
12+
C-h : delete character before the cursor (in insert mode)
13+
C-l : delete character after the cursor (like Del) (in insert mode)
14+
C-w : delete word under cursor (in insert mode)
15+
C-o : execute one normal or command-mode and return to insert (in insert mode)
16+
o : move cursor to opposite side of selection (in visual mode)
17+
U : Uppercase the selection
18+
C-v : Change to visual-bloc mode (from visual mode)
19+
S-v : Change to visual mode (from visual-bloc mode)

plugin/vim-tips.vim

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ let s:vimrc = $MYVIMRC
1313

1414

1515
function Rand()
16+
"ok-tier rng
1617
return str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:])
1718
endfunction
1819

1920

2021

2122
function GetTip()
2223
let s:random_number = Rand()
23-
let s:number_categories = 9
24+
let s:number_categories = 10
2425
let s:chosen_category = s:random_number % s:number_categories
2526

2627
let s:tip = ""
@@ -42,6 +43,8 @@ function GetTip()
4243
let s:tip = GetPhrases()
4344
elseif s:chosen_category == 8
4445
let s:tip = GetSelection()
46+
elseif s:chosen_category == 9
47+
let s:tip = GetOtherModes()
4548
endif
4649
return s:tip
4750
endfunction
@@ -77,6 +80,11 @@ function GetMarkers()
7780
return s:tiplist[s:index]
7881
endfunction
7982

83+
function GetOtherModes()
84+
let s:tiplist = ["C-k (+characters) : insert digraphs (æ,π...) in insert mode","C-K * p : insert π (in insert mode)","C-K Eu : insert € (in insert mode)","C-K +- : insert ± (in insert mode)","C-K OK : insert ✓ (in insert mode)","C-K XX : insert ✗ (in insert mode)","C-K AN : insert ∧ ('and' symbol) (in insert mode)","C-K OR : insert ∨ ('or' symbol) (in insert mode)","C-K (- : insert ∈ (in insert mode)","C-a : insert the last content inserted (in insert mode)","C-@ : insert the last content insert and quit insert mode (in insert mode)","C-h : delete character before the cursor (in insert mode)","C-l : delete character after the cursor (like Del) (in insert mode)","C-w : delete word under cursor (in insert mode)","C-o : execute one normal or command-mode and return to insert (in insert mode)","o : move cursor to opposite side of selection (in visual mode)","U : Uppercase the selection","C-v : Change to visual-bloc mode (from visual mode)","S-v : Change to visual mode (from visual-bloc mode)",]
85+
let s:index = Rand() % len(s:tiplist)
86+
return s:tiplist[s:index]
87+
endfunction
8088

8189

8290

@@ -88,7 +96,7 @@ endfunction
8896

8997

9098
function GetMiscallenous()
91-
let s:tiplist =[":w! sudo tee % :write as root (ask password)","CTRL + w + = :resize splits equally","[[ : jump to function start",":new file.txt : open file.txt in new split","gt : show next tab","=% : indent code between parenthesis","C-w : (in insert mode) erases word from start to position","C-u : (in insert mode) erases line from start to position","// : run your previous search","CTRL + w + x : exchange with next window",]
99+
let s:tiplist =[":w! sudo tee % :write as root (ask password)","CTRL + w + = :resize splits equally","[[ : jump to function start",":new file.txt : open file.txt in new split","gt : show next tab","=% : indent code between parenthesis","C-w : (in insert mode) erases word from start to position","C-u : (in insert mode) erases line from start to position","// : run your previous search","CTRL + w + x : exchange with next window", "set <option> ? : see the value of a config option", "C-k (+characters) : insert digraphs (æ,π...) in insert mode","C-K-*-p : insert π (in insert mode)",]
92100
let s:index = Rand() % len(s:tiplist)
93101
return s:tiplist[s:index]
94102
endfunction
@@ -116,13 +124,65 @@ function GetSelection()
116124
return s:tiplist[s:index]
117125
endfunction
118126

119-
function DisplayTip()
120127

121-
let s:prefix = "Tip => "
122-
echo s:prefix.g:GetTip()
128+
function GetPathTmpFile()
129+
if has('win32')
130+
let tmpfilepath = resolve(expand('<sfile>:p:h')).'\tmp_config'
131+
else
132+
let tmpfilepath = resolve(expand('<sfile>:p:h')).'/tmp_config'
133+
endif
134+
return tmpfilepath
135+
endfunction
136+
137+
function GetConfig()
138+
try
139+
let tmpfilepath =GetPathTmpFile()
140+
let s:configlist = readfile(tmpfilepath)
141+
let s:config= s:configlist[0]
142+
catch
143+
return ""
144+
endtry
145+
return s:config
146+
endfunction
147+
148+
149+
function PrepareNextConfig()
150+
let tmpfilepath = GetPathTmpFile()
151+
if has('win32')
152+
"nothing yet
153+
else
154+
" on UNIX-like OS
155+
silent !sleep 5 &
156+
"instead, start here a bash/python script in background (&) that remove the first line
157+
"of the tmpfile and if it is empty, populate it with the config fetched
158+
endif
159+
endfunction
160+
161+
162+
163+
164+
function DisplayTipOrConfig()
165+
let s:very_random_float = (Rand() % 100) +150
166+
if s:vim_tips_tips_frequency * 100> s:very_random_float
167+
let s:prefix = "Tip => "
168+
echo s:prefix.g:GetTip()
169+
else
170+
let s:configtip = GetConfig()
171+
if s:configtip == "" "failed to get a proper mapping, return a normal tip instead
172+
let s:prefix = "Tip => "
173+
echo s:prefix.g:GetTip()
174+
return
175+
endif
176+
177+
178+
"got a proper mapping
179+
let s:prefix = "Config =>"
180+
echo s:prefix.s:configtip
181+
call PrepareNextConfig()
182+
endif
123183
endfunction
124184

125185

126186
if s:vim_tips_display_at_startup
127-
autocmd VimEnter * call DisplayTip()
187+
autocmd VimEnter * call DisplayTipOrConfig()
128188
endif

0 commit comments

Comments
 (0)