App-Cheats
view release on metacpan or search on metacpan
#############################################################
## Linux Commands - xsel
#############################################################
# Use copy and paste on the command line.
sudo apt install xsel
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
#############################################################
## Linux Commands - xterm
#############################################################
# Resize window (Putty,xterm)
echo -e '\e[8;50;100t'
# Minimize the window for a few seconds, then restore it (Putty,xterm)
echo -e '\e[2t' && sleep 2 && echo -e '\e[1t'
# Move the window to the top/left corner of the display (Putty,xterm)
echo -e '\e[3;0;0t'
# Zoom the window (Putty,xterm)
echo -e '\e[9;1t'
# Bring the window to the front (without changing keyboard focus) (Putty,xterm)
echo -e '\e[5t'
Change the name of an xterm window to "string"
echo -ne "\033]2;string\007"
# Change the name of an xterm icon to "string"
echo -ne "\033]1;string\007"
# Change the name of an xterm icon and window to "string"
echo -ne "\033]0;string\007"
# Create alias to easily change the window name and icon name
# Must be run together!
set_title(){ echo -ne "\033]0;$@\007"; }
alias title='set_title'
# Get dimensions/size of a screen/xterm
xdpyinfo | grep dimensions
xrandr | grep '*'
# Get the size of an xterm window
xwininfo
# Get info about current xterm window
xdpyinfo
# Get size info of a named xterm window
xwininfo -name omsGUI_0_3
# Get info about an xterm window
xprop -id <window_id>
xprop -id 0x2400022
# Get position of the cursor
perl -e '$/ = "R";' -e 'print "\033[6n";my $x=<STDIN>;my($n, $m)=$x=~m/(\d+)\;(\d+)/;print "Current position: $m, $n\n";'
# Print how many columns and rows an xterm window uses for its screen size
tput cols
tput lines
reset
# Change fond/colors of an xterm window
RESTORE='\033[0m'
RED='\033[00;31m'
GREEN='\033[00;32m'
YELLOW='\033[00;33m'
VIOLET='\033[00;35m'
TEAL='\033[00;36m'
GREY='\033[00;37m'
# View color ansi escapes with less (like Vim)
less -R file
# Make xterm text color bold
BOLD='\033[1m'
# Make xterm text color blink
BLINK='\033[5m'
# Move mouse to a specific location on the screen/xterm window (on lnxbr42)
xdotool mousemove 764 11
# Click on a button (cannot on top bar , like the X for close)
xdotool click 1
# Get mouse location
xdotool getmouselocation
# Move mouse to a location and click at the same time
xdotool mousemove 1747 30 click 1
# print contents of X events (mouse activity/movement)
xev
# Install xdotool dependencies
sudo apt-get install libxcb-xtest0:i386 libxcb-xtest0-dbg:i386 libxcb-xtest0-dev:i386
dpkg -l | grep xtest
# Other xdotool dependenacies
sudo aptitude install
# install xdotool from repository
cd ~junk/xdo/xdotool-master
sudo make install
# Check dependencies of a debian package
dpkg -I xdotool_3.20160512.1-1_i386.deb
# Install package from source (.deb)
sudo dpkg -i xdotool_3.20160512.1-1_i386.deb
sudo apt-get install -f
# Launch an xterm window into a certain directory
xterm -e 'cd ~/dsu && /bin/bash'
# < <(_my_function): This redirects the output of _my_function to the
read command.
#############################################################
## Bash - Ascii Art
#############################################################
# Ascii Art
figlet "svn update"
# Nice format for representing binary numbers (art,ascii)
figlet "0000011111" -f digital
# Show all available figlest fonts (ascii art)
figlist | perl -lne '$a=/\bfonts.*:$/ ... /.*:/; print if $a > 1 and $a !~ /E/'
# There are the nicer fonts
banner big lean slant smslant standard
# favorite
slant
figlet "svn update" -f slant
# Center the ascii art (justify)
figlet "svn update" -f slant -c
# Right justify the ascii art and set a width of 60
figlet "svn update" -f slant -r -w 60
#############################################################
## Bash - Autocomplete
#############################################################
# Example of using autocompletion (tab)
/usr/share/bash-completion/completions/perltidy
/usr/share/bash-completion/completions/perl
/usr/share/bash-completion/completions/ip
# Generate autocompletion for own scripts (Bash,Tab)
# Options - aaa aba bbb ccc
_sb_tab(){
COMPREPLY=( $(compgen -W "`sb info`" -- "${COMP_WORDS[COMP_CWORD]}") )
}
complete -F _sb_tab sb
# Colon should not be a word break in perl.
export COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
# View all tab completions (Bash,Tab,auto)
complete
# Delete all tab completions (Bash,Tab,auto)
complete -r
# Use existing autocompletions
complete -p | grep ls # finds _longopt
complete -F _longopt my_function
# Bash autocomplete special variables
# COMP_WORDS is an array containing all individual words in the current command line.
# COMP_CWORD is an index of the word containing the current cursor position.
# COMPREPLY is an array variable from which Bash reads the possible completions.
# Tab completions source of bash commands (Bash,Tab,auto)
vi /etc/bash_completion
vi /usr/share/bash-completion/bash_completion
# Generate autocompletion for own scripts (Bash,Tab)
bash_autotab(){
# COMPREPLY=( $(compgen -W "$*" -- "${COMP_WORDS[COMP_CWORD]}") )
#
local cur="${COMP_WORDS[COMP_CWORD]}"
#
# Get possible words without consider colon characters
_get_comp_words_by_ref -n : cur
#
COMPREPLY=( $(compgen -W "$*" -- "$cur") )
#
# Remove colon contain prefix from COMPREPLY
__ltrim_colon_completions "$cur"
#
# echo "COMP_WORDS = [${COMP_WORDS[@]}]"
# echo "COMP_CWORD = [${COMP_CWORD[@]}]"
# echo "COMP_LINE = [$COMP_LINE]"
# echo "COMPREPLY = [${COMPREPLY[@]}]"
}
otrs_module_install(){
echo "$OTRS_MODULE_TOOLS" Module::Package::Install "$@"
}
_otrs_module_install__tab(){
local possible=( $(ls "$OTRS_PACKGES_DIR") )
#
base_autotab ${possible[*]}
# base_autotab $(ls $OTRS_PACKGES_DIR)
#
# echo "COMP_WORDS = [${COMP_WORDS[@]}]"
# echo "COMP_CWORD = [${COMP_CWORD[@]}]"
# echo "COMPREPLY = [${COMPREPLY[@]}]"
}
complete -F _otrs_module_install__tab otrs_module_install
# Manually run bash tab completion
compgen -W "abc abdd afg" -- ab
# Bash completion location.
So there are 2 places where bash completions can reside:
/etc/bash_completion.d/
- Legacy place.
- Sourced very early on (whether needed or not).
/usr/share/bash-completion/completions/opi
- New place.
- Sourced on demand.
# Where are these defined:
_init_completion
_get_comp_words_by_ref
__ltrim_colon_completions
#
/etc/bash_completion
# Where are these defined:
spinner.className = "center loader";
svg_box.className = "center loading-svg";
#
screen.append(canvas);
screen.append(spinner);
screen.append(svg_box);
svg_box.appendChild(logo);
#
svg_box.addEventListener("click", hide_loading);
show_glass();
#
// Setup
const radius = 75; // Inner circle radius
const ctx = canvas.getContext('2d');
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
ctx.beginPath();
#
// Draw shape
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = '#ffffff'; // light grey
ctx.fill();
}
# Create a simple CSS/HTML animation (blink an element)
.blink {
animation: blinker 2s linear infinite;
}
@keyframes blinker {
50% {
opacity: 0.5;
}
}
# Function to unshow the loading spinner
function hide_loading(){
const screen = document.querySelector("#glass");
#
if(screen.children.length){
setTimeout(() => {
while(screen.firstChild)
screen.removeChild(screen.firstChild);
hide_glass();
}, 500);
}
else{
hide_glass();
}
}
# CSS for the loading spinner
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.loading-svg {
width: 5.7375rem;
height: 2.23125rem;
cursor: pointer;
}
.loading-svg svg > path, .loading-svg svg > ellipse, .loading-svg svg > rect {
fill: #888;
}
.loading-svg svg > .thicker {
fill: #888;
}
.loading-svg svg > .thinner {
fill: #777;
}
.loader {
border-top: 2px solid #777; /* dark */
border-bottom: 2px solid #777; /* dark */
border-left: 2px solid #ccc; /* light */
border-right: 2px solid #ccc; /* light */
border-radius: 50%;
height: 150px; /* Diameter of ring */
width: 150px; /* Diameter of ring */
margin-top: -77px; /* height/2 + border */
margin-left: -77px; /* width/2 + border */
animation: spin 3s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#############################################################
## Javascript - Strings
#############################################################
# Capitalize first letter of a word in Javascript
string = string.charAt(0).toUpperCase() + string.slice(1);
# Addition versus concatenation (javascript,to integer)
5 + 2 => 7
"5" + "2" => 52
"5" + 2 => 52
Number("5") + Number("2") => 7
Number("5") + 2 => 7
# Javascript convert a string to lowercase (uppercase is similar)
"AAA".toLowerCase()
# Javascript check if a variable is defined
if(typeof file_root_name == 'undefined'){
return;
}
if(file_root_name == null){
return;
}
# String interpolation in javascript (only with backticks and curlys)
n = 123
console.log("here is: ${n}") // here is: ${n}
console.log('here is: ${n}') // here is: ${n}
console.log(`here is: ${n}`) // here is: 123
console.log(`here is: $n` ) // here is: $n
# Get name of raspberry pi
cat /sys/firmware/devicetree/base/model
Raspberry Pi 3 Model B Plus Rev 1.3
# Check pi revision
cat /proc/cpuinfo
Code Model Revision RAM Manufacturer
a020d3 3B+ 1.3 1GB Sony UK
#
# Compare to:
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
# Find out the total on a linux machine (pi)
local ram=$(\grep MemTotal /proc/meminfo | perl -lne '($kb)=/(\d+)/; printf "%0.2fGB", $kb/1024/1024')
#############################################################
## PI - Network Interface
#############################################################
# Turn interface card off and on. (pi)
# Useful in cases where connection needs to be reset.
sudo ifconfig eth0 down && sudo ifconfig eth0 up
# Add a static IP address in Linux (pi,debug,Workarounds)
# Workaround for when DHCP does not work with the firewall
su # super user mode
mount -o remount,rw / # mount the filesystem
vi /etc/network/interfaces # update interfaces
auto eth0 # Add these lines
iface eth0 inet static
address 172.17.17.10
netmask 255.255.255.0
gateway 172.17.17.1
/etc/init.d/networking restart # restart the service
vi ~/webpage.sh
#IP=$(dhcpcd --dumplease eth0 | grep routers | cut -d\' -f2)
IP=172.17.17.1
reboot
#
The different keywords have the following meaning: (pi,debug,interfaces)
auto: the interface should be configured during boot time.
iface : interface
inet: interface uses TCP/IP networking.
#############################################################
## PI - Options
#############################################################
# Reduce blinking (pi)
sudo vi /boot/config.txt
/ hdmi_mode=82 # Original
# https://elinux.org/RPiconfig
82 1080p 60Hz Original
83 1600x900 Reduced blanking. Too small. Must scroll, plus keyboard is mostly gone)
84 2048x1152 Reduced blanking. Double size. Unreadable
85 720p 60Hz Good. But need to scroll
# Smart toggle (enable/disable) mouse cursor (pi)
# Remove/add "-nocursor" to this line:
# MUST first mount / then restart
sudo mount -o remount,rw /
sudo vi /etc/lightdm/lightdm.conf
/ xserver-command=X -nocursor
sudo reboot
#############################################################
## PI - Shortcuts
#############################################################
# Open Terminal on Linux (pi)
Control + Alt + T
# Maximize terminal window on Linux (debug)
Control + Alt + Up
# Switch between windows/terminal in Rasberry Pi (pi)
Alt + Tab
# Force a hard reboot that may cause a "Connection Reset by Peer" Error
sudo reboot -f
Alt + Druck + b
# Get control back of linux, save data and reboot (stuck,terminal)
#
# 1. Hold down the Alt and SysRq (Print Screen) keys.
# 2. While holding those down, type the following keys in order, several seconds apart: R E I S U B
# 3. Computer should reboot.
# unRaw (take control of keyboard back from X),
# tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
# kIll (send SIGKILL to all processes, forcing them to terminate immediately),
# Sync (flush data to disk),
# Unmount (remount all filesystems read-only),
# reBoot.
#############################################################
## PostgreSQL (psql)
#############################################################
# Install psql
sudo apt install postgresql postgresql-contrib postgresql-server-dev-13 gcc
sudo apt-get install libdbd-pg-perl
cpan DBD::Pg
#############################################################
## Powershell
#############################################################
# Regular Expression Named Capture in Powershell
" dev master * release/2.00" -match "release/(?<MAJOR>\d+)\.(?<MINOR>\d+)"
echo $Matches
echo $Matches.MAJOR
echo $Matches.MINOR
#############################################################
## Python General
#############################################################
# Zen of Python (motto)
python -c 'import this'
# ZFS list snapshots
zfs list -r -t snapshot -o name,creation
# Send snapshot backup
sudo zfs send rpool/USERDATA/tim_e5bkz1@autozsys_zh25vd | sudo zfs receive brpool/USERDATA
# Send incremental backup
sudo zfs send rpool@june15b | sudo zfs receive -Fd brpool
# Mount external hard drive with ZFS
sudo zpool list # Show available pools
sudo zpool import # Shows the brpool name
sudo zpool import brpool # Import brpool
sudo zpool list # Pool now added
# Create a Snapshot with a specific text
sudo zfs snapshot rpool/USERDATA/tim_e5bkz1@june15
# View mounting options for ZFS (zpool)
sudo zfs get 'mountpoint,mounted,canmount' brpool/USERDATA
# zpool status is SUSPENDED
sudo zpool clear brpool
sudo zpool clear -nFX brpool # Or this
# Cleanup rpool space for zfs
zfs list -t snapshot -o name | while read f; do sudo zfs destroy -r $f; done
#############################################################
## Ubuntu - Flashdrive
#############################################################
# Make bootable flashdrive from iso file (ubuntu)
# Startup Disk Creator
# https://ubuntu.com/tutorials/create-a-usb-stick-on-ubuntu#3-launch-startup-disk-creator
# Automount external hard drive
vi /etc/fstab
UUID=E2B4CF51B4CF273F /media/MY_BACKUP auto nosuid,nodev,nofail,x-gvfs-show 0 2
#
# Find out ID by running
sudo fdisk -l
blkls /dev/<DEVICE>
#
# Or find UUID here for the device
ls -l /dev/disk/by-uuid/
# Backup PC in Ubuntu using timeshift (not for zfs)
https://linuxconfig.org/ubuntu-20-04-system-backup-and-restore
# Allow writing to flash drives
sudo chown $USER:$USER /media/<USER>-srto/ -R
#############################################################
## Ubuntu - Update Error
N#############################################################
# Problem: Did a partial upgrade,
# Ubuntu restarted to a black screen and a blinking cursor.
# Fix:
Control + Alt + F2 # At the same time
#
# Login to PC
#
# Finish upgrade
sudo apt update
sudo apt dist-upgrade
sudo startx
#############################################################
## Ubuntu - Drivers
#############################################################
# Reload sound drivers on Ubuntu
sudo alsa force-reload
#############################################################
## Ubuntu - BIOS
#############################################################
# Check BIOS version on the command line (BIOS update).
sudo dmidecode -s bios-version
# Current: N34ET58W (1.58 )
# Old: N34ET52W (1.52 )
# Find serial number in Ubuntu (BIOS update).
sudo dmidecode -t system | grep Serial # PF2SHW37
# Update BIOS on Ubuntu Lenovo
# 1. Download iso file from here:
https://pcsupport.lenovo.com/cz/en/products/laptops-and-netbooks/thinkpad-p-series-laptops/thinkpad-p14s-gen-2-type-20vx--20vy/20vx/20vx0010ge/pf2shw37/downloads/driver-list/component?name=BIOS%2FUEFI&id=5AC6A815-321D-440E-8833-B07A93E0428C
# 2. Flash iso file to harddrive:
Downloads -> Right Click on iso file
-> Open with other
-> Disk image writer.
# 3. Restart PC -> Enter -> F12 -> Select HD.
# Run a system update on Ubuntu
sudo fwupdmgr update # Updates only the firmware.
#
sudo fwupdmgr install N34ET53W.cab
# (Can get the cat file from:
# https://pcsupport.lenovo.com/de/de/downloads/ds548904-bios-update-utility-bootable-cd-for-windows-10-64-bit-thinkpad-p14s-gen-2-p15s-gen-2-t14-gen-2-t15-gen-2
#)
# During startup would see:
Reading ME failed.
# This fixed it:
sudo fwupdmgr reinstall
# Select 'Intel Management Engine' option.
#############################################################
## Ubuntu - Power
#############################################################
# Change Ubuntu from suspending when the lid is closed.
let new_variable s = ubstitute("My::Long::Package", "::", "/", "g")
let old_variable = "My::Long::Package"
let new_variable = substitute(old_variable, "::", "/", "g")
# Check if a string or variable contains a pattern (vim)
echo "My::Package" =~ "::" # 1
let var = "My::Package"
if var =~ "::"
echo "Got a perl package"
endif
#############################################################
## Vim File Operations
#############################################################
# Check if a file is readable (vim,exists)
if filereadable(l:filename) == 1
execute "edit" l:filename
else
echohl WarningMsg | echo "File does not exist: " . l:filename | echohl None
endif
#############################################################
## Vim Funtions
#############################################################
# Prefix vim function arguments with a:
let l:filename = a:package_name
#############################################################
## Vim Custom Commands
#############################################################
# Create a custom command with arguments (vim)
+ function CustomEdit(package_name)
+ let l:filename = a:package_name
+
+ if l:filename =~ "::"
+ let l:filename = substitute(l:filename, "::", "/", "g")
+ let l:filename = l:filename . ".pm"
+ endif
+
+ if filereadable(l:filename) == 1
+ execute "edit" l:filename
+ else
+ echohl WarningMsg | echo "File does not exist: " . l:filename | echohl None
+ endif
+
+ endfunction
+
+ :command! -nargs=1 E call CustomEdit(<f-args>)
#############################################################
## Vim Inserting Text
#############################################################
# Insert before cursor (Vim)
i
# Insert before line (Vim)
I
# Append after cursor (Vim)
a
# Append after line (Vim)
A
# Open a new line after current line (Vim)
o
# Open a new line before current line (Vim)
O
# Replace one character (Vim)
r
# Replace many characters (Vim)
R
# Insert 50 characters (Vim)
50i-
50a-
50A-
# Append to the end of a word (Vim)
ea
# Join next line to current line (Vim)
J
3J # join 3 lines (including current)
# Repeat last command (Vim)
.
# Insert a timestamp before each line labeled "SECTION" (Vim,read file,external,run)
:g/SECTION/-1 r !date
# View whitespace, line endings (Vim,hidden)
:set list
# Count the number of each of function call (DES,UI,Vim,variable)
# If there is a space before "\=i", "i" will not be interpreted.
# (same goes for "i++".
:let i=1
:g/myps()/ s!$! // ! | s/$/\=i/ | let i+=1 # In: ui.c
:g/myps(\d\+);/ s!\d\+!\=i! | let i+=1 # In: snvtb.c
# Insert 2 blank lines above "CREATE TABLE" line (Vim)
:g/\v^CREATE TABLE/ :norm 2O
# Append to an option or setting (Vim)
:set tags=abc
:set tags+=def
# Increase indentation (Vim,tab)
>>
# Decrease indentation (Vim,tab)
<<
# Move specific lines to the end of the file (Vim)
:g/item/ :move $
# Move a sentence back (Vim)
(
# Move a sentence forward (Vim)
)
# Move a paragraph back (Vim)
{
# Move a paragraph forward (Vim)
}
# Move to the begining of the line (Vim)
0
# Move to the end of the line (Vim)
$
# Move to the first line of the file (Vim)
1G
# Move to the last line of the file (Vim)
G
# Move to nth line of the file (Vim)
nG
# Move to nth line of the file (Vim)
:n
# Move forward to c (Vim)
fc
# Move back to c (Vim)
Fc
# Move to top of screen (Vim)
H
# Move to middle of screen (Vim)
M
# Move to botton of screen (Vim)
L
# Move to associated ( ), { }, [ ] (Vim)
%
# Go to start of word from anywhere in the word (Vim)
lb
# Select again the last visual selection (Vim)
gv
#############################################################
## Vim Deleting Text
#############################################################
# Delete character to the right of cursor (Vim)
x
# Delete character to the left of cursor (Vim)
X
# Delete to the end of the line (Vim)
D
# Delete current line (Vim)
dd
# Delete current line (Vim)
:d
# Delete text to beginning of line when in insert mode (Vim)
<Control> + u
#############################################################
## Vim Copy(Yank) and Paste Text
#############################################################
# Yank the current line (Vim)
yy
# Yank the current line (Vim)
:y
# Change to the end of the line (Vim)
C
# Change the whole line (Vim)
cc
# Put after the position or after the line (Vim)
p
# Put before the poition or before the line (Vim)
P
# Move block from "SECTION 1" to but not including "SECTION 2" (Vim)
# Move that block to right before "SECTION 3"
:g/SECTION 1/.,/SECTION 2/-1 move /SECTION 3/-1
#
# Approach in perl
perl -lne '$n=/SECTION 1/.../SECTION 2/; push @a,$_ and next if $n and $n !~ /E0$/; if(/SECTION 3/){print for @a}; print' vim_comp
perl -lne 'INIT{$"="\n"} $n=/SECTION 1/.../SECTION 2/; push @a,$_ and next if $n and $n !~ /E0$/; /SECTION 3/ and print "@a"; print' vim_com
# handles multiple such blocks
perl -lne 'INIT{$"="\n"} $n=/SECTION 1/.../SECTION 2/; push @a,$_ and next if $n and $n !~ /E0$/; /SECTION 3/ and print "@a" and undef @a; print' vim_comp
# Delete "SECTION 2" (end marker is "SECTION 3" exclusive (Vim)
:g/SECTION 2/,/SECTION 3/-1d
#
# Approach in perl
perl -lne '$a=/SECTION 2/.../SECTION 3/; print unless $a and $a !~ /E0$/' vim_comp
#############################################################
## Vim Markers
#############################################################
# Set marker c on this line (Vim)
mc
# Replay last macro (Vim,run)
@@
# Repeat movement and commands (Vim)
qq;.q # next, repeat command
11@q # run 11 times
# Number a list of lines (Vim)
:let @c=0 # set value of register (preload)
:let @n=0i^R=^Rc+1^M. ^[0"cywj^[ # will not work with control characters
# Run macro commands in parallel (Vim)
:let @a='0f.r)w~' # load macro
<Shirt> + V + G # Select current line to end
:normal @a # run macro on lines
# Select desired lines in file and run macro on them (Vim,global)
:g /^sched_args/ :normal @c
# Append to existing register (Vim,typo)
qa # start original macro
... # commands
q # stop recording
qA # Captial means append to register "a"
... # Fix typo
q # End
# Indent the description section in primitives_doc file (Vim)
# This commands finds any problems
:g/^\v Syntax:.*\n\n/ .+2,/^\v [a-zA-Z]+:/-2p
#
# This will transform.
# 1. Find all "Syntax:" lines.
# 2. Assume next is blank, so start 2 lines down "+2".
# 3. Search for the next section and end 2 above that "-2".
# 4. Strip any leading space and replace with 6 spaces.
# 5. Strip trailing whitespace.
g/^\v Syntax:.*\n\n/ .+2,/\v^ [a-zA-Z]+:/-2 s/^\v\s*(\S+)@=/ / | s/\s\+$//
#############################################################
## Vim Folding
#############################################################
# Manually fold a sectin (Vim)
v + <move_arrows> + zf
# Fold next 3 lines (Vim)
zf3j
# Allow folding of perl code (Vim)
let perl_fold=1
# Can put in rc file. related to folding. not sure (Vim)
:setlocal foldmethod=syntax
inoremap <F9> <C-O>za
nnoremap <F9> za
onoremap <F9> <C-C>za
vnoremap <F9> zf
# Close a fold (depends on cursor) (Vim)
zc
# Close all fold (depends on cursor) (Vim)
zC
# Open a fold (depends on cursor) (Vim)
zo
# Open all fold (depends on cursor)
zO
# Toggle/Alternate a fold (depends on cursor) (Vim)
za
# Toggle/Alternate all fold (depends on cursor) (Vim)
zA
# Open a single level of folds (depends on cursor) (Vim)
zr
# Open all more level of folds (seems similar to zA) (Vim)
zR
# Close a single level of folds (Vim)
zm
# Close all more level of folds (seems similar to zC) (Vim)
zM
# File should open unfolded (Vim)
set nofoldenable
#############################################################
## Vim Perl
#############################################################
# Help for perl syntax in vim.
:h perl.vim
#############################################################
## Vim Profiling
#############################################################
# Check what is running slow in vim (profile).
:syntime on
# *** Do some slow actions ***
:syntime report
# Start vim with no config file (profiling)
vim -u NONE FILE_NAME
# Exit early from vimrc (Profile,script,exit,return,continue)
finish
#############################################################
## Vim Multiple Screens (Window/Split)
#############################################################
# Split screen horizontally (Vim,up and down)
<Control> + w + s
# Split screen vertically (Vim,left and right)
<Control> + w + v
# Move to the screen below (Vim,multiple)
<Control> + w + j
# Close all other screen (Vim,multiple)
<Control> + w + o
# View the window number of current screen (Vim)
:echo winnr()
# Go to a specific window (Vim,screen)
:1wincmd w
# Show the current buffer number (Vim,multiple)
:echo bufnr("%")
# Put current windows to the a side (Vim,multiple,screens)
<Control> + w + K # Up
<Control> + w + J # Down
<Control> + w + H # Left
<Control> + w + L # Right
# Load a buffer number (file) into the current window (Vim,multiple)
:hide buf<number>
:hide buf4
# Run command in every buffer (Vim,multiple screens)
:bufdo! %s/ABC/123/g
" Saving .vimrc should reload the buffer.
" Example of running multiple vim commands.
augroup save_vimrc
autocmd!
autocmd bufwritepost $MYVIMRC source $MYVIMRC | bufdo call RemovePerlSyntax()
augroup END
# Close all other windows (Vim,multiple screens)
:on
:on!
:only
:only!
#############################################################
## Vim Sessions (Save and Restore Display)
#############################################################
# Save current display (Vim,session)
:mksession ~/bin/vim/lwp.vim
:mks ~/bin/vim/lwp.vim
# Restore a select display (Vim,session)
vim -S ~/bin/vim/lwp.vim
# Save current display (Vim,session)
# Pressing "-s" will save the display
# Pressing "-r" will restore the last saved display
#############################################################
## Vim Tags
#############################################################
# Create a tags file (Vim)
sudo apt-get install exuberant-ctags
ctags <c_file>
ctags -f $tag -R $source --totals
# Create tags of all OMS functions (Vim)
sudo apt-get install exuberant-ctags
ctags `find ~/omspp/trunk/ -type f -name "*.[ch]" -o -name "*.cpp"`
ctags -f $tag_file $(find $oms_tree -type f -name "*.[ch]" -o -name "*.cpp")
# Jump to the tag/function underneath the cursor (Vim)
<Control> + ]
:tag
# Search for a particular tag (Vim)
:ts <tag>
# Go to the next definition for the last tag (Vim)
:tn
# Go to the previous definition for the last tag (Vim)
:tp
# List all of the definitions of the last tag (Vim)
:ts
# Jump back up in the tag stack (Vim)
<Control> + o # One jump in jump list
<Control> + t # Can be many jumps
#############################################################
## Vim Tab Spacing (Indentation)
#############################################################
# Increase indentation (with autoindent set) (Vim)
<Control> + T
# Descrease indentation (with autoindent set) (Vim)
<Control> + D
# Indent the next 2 lines (Vim)
>2j
# Indent all the lines to the end of the file (Vim)
>G
#############################################################
## Vim Syntax
#############################################################
# Comment lines in vimrc should start with "
" this is a comment
# Name of file that is opened in vim
let _curfile = expand("%:t")
# Show line numbers in vim (vimrc)
set number
# Vim resource (vimrc) file. other features.
set nowrap
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40
set cursorcolumn
# Do not go past the end of the file when searching (Vim)
set nowrapscan
# View the current file type of a Vim file
:set filetype?
# Check the file type (Vim,xterm,shell)
file ~/bin/enter_ui.sh
# Force the syntax to be a certain type in Vim
:set syntax=perl
#############################################################
## Vim Case Changing
#############################################################
# Toggle upp and lower case (Vim)
~
# Toggle case of the next three characters (Vim)
3~
# Toggle case of the next three words (Vim)
g~3w
# Toggle case of the current word (inner word - cursor anywhere in word (Vim)
g~iw
# Toggle case of all characters to end of line (Vim)
g~$
# Toggle case of the current line (Vim)
g~~
V~
# Uppercase the visually-selected text (Vim)
v
U
# Lowercase the visually-selected text (Vim)
v
u
# Change the current line to uppercase (Vim)
gUU
VU
# Change the current line to lowercase (Vim)
guu
Vu
# Change current word to uppercase (Vim)
gUiw
# Change current word to lowercase (Vim)
guiw
# Disable Caps Lock (Vim)
xmodmap -e "remove Lock = Caps_Lock" -e "keysym Caps_Lock = Escape"
# Enable Caps Lock (Vim)
xmodmap -e "keysym Escape = Caps_Lock" -e "add Lock = Caps_Lock"
# Other mappings for xmodmap (Vim,Shell)
vi /usr/include/X11/keysymdef.h
#############################################################
## Vim Script/Coding Structures (Functions
#############################################################
# Comparison in conditional (Vim,equal)
:if 1 == 1 | echo "TRUE" | else | echo "FALSE" | endif
# TRUE
# Comparison in conditional (Vim,equal,strings)
:if "abc" == "abc" | echo "TRUE" | else | echo "FALSE" | endif
# TRUE
# Comparison in conditional (Vim,equal,strings)
:if "abc" == "def" | echo "TRUE" | else | echo "FALSE" | endif
# FALSE
# Comparison in conditional (Vim,equal,strings)
:if "10abc" == "10def" | echo "TRUE" | else | echo "FALSE" | endif
# FALSE
( run in 3.453 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )