Don't wanna be here? Send us removal request.
Text
My vim cheatsheet
Edit file in the same instance of VIM: :e <filename>
Edit command (possible to paste yanked text inside command text): : then C-f - Useful for command history as well :D
Split horizontally in the same vim instance: :sp <filename>
Undo: u
Redo: C-r
Increase/Decrease window size vertically: C-w+ / C-w-
Split vertically: :vsplit with C-w> and C-w< to increase/decrease size vertically
Make splits equal: C-w=
Folding: if section already folded zo opens it, zc closes it (if stuff ain't foldin' just :set foldenable)
Folding: visual mode, select section, then zf to fold
Maximize tab (keep only the current tab in view, all other tabs must have contents saved): C-wo
Minimize tab: C-w^
Maximize window (buts keep other tabs visible): C-w| (vertically) C-w_ (horizontally) Swap windows: C-wr (rotate)
Buffer fun: :buffers :ls :badd, :bnext, :b# (# is the buffer number) - I don't use this as much
Sed replace: in all lines: :%s/something_old/something_new/g[c - confirmation][i - ignore case]
Show current file path: 1 C-G (show absolute path), C-G (show relative path to vim's current directory)
Open file in new tab: :tabe
Move to tab: :tabnext :tabprevious :tabn gT gt
Go To Line: :#linenumber
To join two lines: J (SHIFT-j)
Add new line below current and start editing: o
Wild menu (selection visible): :set wildmenu
Changing the syntax colors: set filetype=
Go to beginning of file: gg, go to end of file: G
Show fielename in status bar: C-g, show filename in status bar with absolute path: 1 C-G
Marks (kinda like bookmarks in visual studio): m<letter> - to set a mark, '<letter> - to go to a mark
Working with registers: make a selection using visual mode, then "<letter><action> then to insert that register invoke it the same way, or if in insert mode you can C-r and then the letter assigned to that register and that will paste its value (useful for when using the filename: register is %)
Tabstops and tab size (useful for editing code, if editing config files better keep the default: 8) set tabwidth=4 - determines the size of a displayed tab set shiftwidth=4 - determines how much is inserted when you press tab If these two values differ then vim tries to supplement spaces to allow the set size in shift width (if tabwidth=4 and shiftwidth=6 then pressing tab will add \t[ ][ ] a tab and two spaces)
Recording: Record a set of actions by pressing q, then a letter as a label to be later reused when playing back the set of actions, then q again to stop recording, then @ and the name of the record
0 notes
Text
Bash with superpowers
Regexes... not really
If you’re like me and like to use regexes on your vars then you might be interested in using the extglob shell option shopt -s extglob This makes the pattern matching in variable substitution smarter, allowing you to use a fancy syntax that's not quite the old regexes you're used to.
?(pattern_list) zero or one *(pattern_list) zero or more +(pattern_list) one or more @(pattern_list) one of the given patterns !(pattern_list) anything except one of the given patterns
The patterns are usually the same kind as those used in globbing, so it's basically filename expansion. Also, ksh93 has some extras, like nice already defined stuff like [:alnum:] or [:blank:] but we don't like ksh, it's not default.
Sauces:
Linux Journal Bash Hackers Wiki
1 note
·
View note
Text
Dem tests
Had some fun a few days ago with tests in ksh. What I was doing was I wanted to make an or between two expressions and I was mixing up negations with the OR logical expression.
if [[ ! ( $# -eq 1 ) -o ! ( $# -eq 2 ) ]]; then … fi
Problem here was I was trying to detect cases where a wrong number of arguments were being passed to my scripts and didn’t think the ! should’ve been INSIDE the brackets.
if [[ ( ! $# -eq 1 ) -o ( ! $# -eq 2 ) ]]; then … fi
Best reference is either look this up in a book or
man test
Usually the [ ] tests in conditionals actually behave like test, the [[ ]] ones do the same and also some extra stuff like smarter matching on strings (globbing). I usually like to use the [[ ]] tests in scripts exactly because of that pattern matching they allow.
Live and learn… heh
0 notes
Text
LD_LIBRARY_PATHs
Hi,
I came across a really “nice” problem today: what library’s loaded from where and what env variables do I need to set to the right one loading. This sent me flying through some good old times with the linker so I thought I’d post some links on what investigation I did.
Linux uses just one environment variable to get libraries that are not found in the loader cache (the magical area that gets built with ldconfig): LD_LIBRARY_PATH. There’s some other LD_PRELOAD var, nobody wants this. Other *nixes have different vars.
So I’m gonna dump some links which get more programmery than opsy towards the end they’re nice.
_http://www.markusbe.com/2009/09/about-running-32-bit-programs-on-64-bit-ubuntu-and-shared-libraries/ _
_https://en.wikipedia.org/wiki/Dynamic_linker _
_http://unix.stackexchange.com/questions/116327/loading-of-shared-libraries-and-ram-usage _
man ld.so
If you’re a systems programmer you gotta read this: https://cseweb.ucsd.edu/~gbournou/CSE131/the_inside_story_on_shared_libraries_and_dynamic_loading.pdf
0 notes
Text
All those terminal keys
In order to see all your special keys for the terminal use stty -a You can play around with them and see what each does. Never tried to remap them.
0 notes
Text
Traps and signals
So today I had to look into some scripts that have some traps in ‘em. Interesting enough I figured these things must be linked to all those nice signals we learned about in the operating systems courses.
So I man 7 signal and guess what, ERR isn’t there. Found this page later (cause I’m actually working in ksh, in bash there’s one more) http://docstore.mik.ua/orelly/unix/ksh/ch09_01.htm.
So basically you can trap on a signal like this:
trap “echo ‘Where are you Lucy? “’ DEBUG
and then if you echo “Here I am!” you’ll get the “Where are you Lucy?” text before your call. It’s useful to trace the commands in a script and it was quite fun to discover.
0 notes
Text
Vars in vars
Found a neat thing about variables in variables in bash. So without further ado:
var1=“I’m the real var1″
var2=var1
you can actually echo the value of var1 by referring to var2 as its contents can name the variable you really wanna look at.
echo ${!var2}
1 note
·
View note