31 May 2022
26 May 2022
How to find the files which you have viewed or edited in time order?
23 May 2022
How to delete all the lines which contain a pattern in vim?
The ex command g
is very useful for acting on lines that match a pattern. You can use it with the d
command, to delete all lines that contain a particular pattern, or all lines that do not contain a pattern.
For example, to delete all lines containing "profile" (remove the /d
to show the lines that the command will delete):
:g/profile/d
More complex patterns can be used, such as deleting all lines that are empty or that contain only whitespace:
:g/^\s*$/d
To delete all lines that do not contain a pattern, use g!
, like this command to delete all lines that are not comment lines in a Vim script:
:g!/^\s*"/d
Note that g!
is equivalent to v
, so you could also do the above with:
:v/^\s*"/d
The next example shows use of \|
("or") to delete all lines except those that contain "error
" or "warn
" or "fail
" (:help pattern):
:v/error\|warn\|fail/d
22 May 2022
How to pass args to a Python program when running it?
17 May 2022
16 May 2022
15 May 2022
How to do auto complete in vim?
14 May 2022
How to get a list of the members of an email distribution list, and a list of the members of an office 365 team?
How to read a text file in Python?
Method #1
Method #2
Method #3
Method #4
13 May 2022
How to export a list of members of an email group from Office 365?
Based on my tests and researches, it is not feasible to export distribution list members using UI interface. We can only export the members via Windows PowerShell. To do that, the steps are as follows:
1. Open Windows PowerShell and connect to Exchange Online PowerShell. Here are the commands:
Install-Module ExchangeOnlineManagement (Enter Y to install the module)
Connect-ExchangeOnline (Sign in using admin account and password)
2. Then run the following script to get a csv file about Distribution list.
$Groups = Get-DistributionGroup
$Groups | ForEach-Object {
$group = $_.Name
$members = ''
Get-DistributionGroupMember $group | ForEach-Object {
$members=$_.Name
New-Object -TypeName PSObject -Property @{
GroupName = $group
Members = $members
EmailAddress = $_.PrimarySMTPAddress
}}
} | Export-CSV "C:\DistributionGroupMember.csv" -NoTypeInformation -Encoding UTF8
Here is a screenshot about the result I got:
10 May 2022
How to install vim plugin from github?
How to split a window and let the new window be on the right or below?
Understanding buffers, windows and tabs in vim
08 May 2022
How to show vertical line in Vim?
to display vertical lines
:set colorcolumn=5,9,13,17
Not to display vertical lines
:set colorcolumn=0
How to install and use a vim plugin manager? How to install a vim plugin?
How to split window and open terminal in vim?
https://dev.to/mr_destructive/vim-terminal-integration-4pfp
^w v
To split window vertically. (the same file is opened in the new split window.)
^w l
To go to the newly split windows on the right
:term
To open a terminal. (The window on the right split horizontally, and the terminal window is on the top.)
^w j
To go to the split window below the terminal window
^w c
To close the window below the terminal window
06 May 2022
How to find the files which were modified in the last x minutes
find . -mmin -60 -type f -exec ls -l {} +
05 May 2022
How to capitalise selected words in vim
\<
matches the start of a word.
matches the first character of a word\u
tells Vim to uppercase the following character in the substitution string(&)
&
means substitute whatever was matched on the left-hand sideg
means substitute all matches, not only the first
:help case
says:
To turn one line into title caps, make every first letter of a word
uppercase:
: s/\v<(.)(\w*)/\u\1\L\2/g
Explanation:
: # Enter ex command line mode.
space # The space after the colon means that there is no
# address range i.e. line,line or % for entire
# file.
s/pattern/result/g # The overall search and replace command uses
# forward slashes. The g means to apply the
# change to every thing on the line. If there
# g is missing, then change just the first match
# is changed.
The pattern portion has this meaning:
\v # Means to enter very magic mode.
< # Find the beginning of a word boundary.
(.) # The first () construct is a capture group.
# Inside the () a single ., dot, means match any
# character.
(\w*) # The second () capture group contains \w*. This
# means find one or more word characters. \w* is
# shorthand for [a-zA-Z0-9_].
The result or replacement portion has this meaning:
\u # Means to uppercase the following character.
\1 # Each () capture group is assigned a number
# from 1 to 9. \1 or back slash one says use what
# I captured in the first capture group.
\L # Means to lowercase all the following characters.
\2 # Use the second capture group
Result:
ROPER STATE PARK
Roper State Park
04 May 2022
How to wrap line and un-wrap line in vim?
02 May 2022
Input CSV File:
country, population
Usa, 1273
Usa, 4343
Usa, 1240
Uk, 7879
Uk, 3224
Uk, 4342
Tr, 6565
Tr, 7889
Tr, 1980
========================
import csv
index = {}
with open('/tmp/data.csv') as f:
cr = csv.reader(f)
next(cr) # skip header row
for row in cr:
index.setdefault(row[0], []).append(int(row[1]))
print("['country', 'avgPop']")
for c, v in index.items():
print("['{}', '{}']".format(c, int(sum(v) / len(v))))
Result:
['country', 'avgPop']
['Usa', '2285']
['Uk', '5148']
['Tr', '5478']
01 May 2022
How to slice a number of columns from a 2-dimensional list in Python?
How to pick up a single column from a 2-dimensional list in Python?
a = [[4.0, 4, 4.0], [3.0, 3, 3.6], [3.5, 6, 4.8]]
You can get the index [0]
from each element in a list comprehension
>>> [i[0] for i in a]
[4.0, 3.0, 3.5]