Skip to content

Instantly share code, notes, and snippets.

You mention cutting with yy and complain that you almost never want to cut whole lines. In fact programmers, editing source code, very often want to work on whole lines, ranges of lines and blocks of code. However, yy is only one of many way to yank text into the anonymous copy buffer (or "register" as it's called in vi).

The "Zen" of vi is that you're speaking a language. The initial y is a verb. The statement yy is a synonym for y_. The y is doubled up to make it easier to type, since it is such a common operation.

This can also be expressed as dd P (delete the current line and paste a copy back into place; leaving a copy in the anonymous register as a side effect). The y and d "verbs" take any movement as their "subject." Thus yW is "yank from here (the cursor) to the end of the current/next (big) word" and y'a is "yank from here to the line containing the mark named 'a'."

If you only understand basic up, down, left, and right cursor movements then vi will be no more productive than a copy of "notepad"

@hello = internal constant [21 x i8] c"hello, world %d - %f\00"
declare float @llvm.cos.f32(float %Val)
declare i32 @printf(i8* noalias nocapture, ...) nounwind
define fastcc i32 @main(i32 %argc, i8** %argv) nounwind {
start:
; Cast i8 array to pointer
%ptr = getelementptr [21 x i8]* @hello, i64 0, i64 0
%cos = call float @llvm.cos.f32(float 3.0)
%token keyword_nil
%token tLPAREN tRPAREN // ()
%token tLBRACE tRBRACE // {}
%token tLBRACKET tRBRACKET // {}
%token tPIPE // |
%token tCOLON // :
%token tSEMICOLON // ;
%token tDOT // .
%token tCOMMA // ,
%union {
double dbl;
char *text;
}
%token <text> tLPAREN tRPAREN /* () */
%token <text> tLBRACE tRBRACE /* {} */
%token <text> tLBRACKET tRBRACKET /* {} */
%token <text> tPIPE /* | */
%token <text> tCOLON /* : */
@fjolnir
fjolnir / macro.m
Created May 30, 2012 01:17
The weirdest macro expansion
#define TQAssertSoft(cond, domain, code, fmt, ...) \
do { \
if(!(cond)) { \
if(aoError) \
*aoError = [NSError errorWithDomain:(domain) code:(code) userInfo:nil]; \
TQLog(fmt, ##__VA_ARGS__); \
return NO; \
} \
} while(0)
class Foo < Bar
+ method: arg1 with: arg2 {}
- instanceMethod {}
end
is parsed to:
<cls@ class <ident@ Foo> < <ident@ Bar>
<meth@ + <arg@ method: <ident@ arg1>> <arg@ with: <ident@ arg2>> {}>
@fjolnir
fjolnir / output.sh
Created May 30, 2012 16:34
Tranquil parser test
> build/tranquil < test.tq
<msg@ <acc@ <var@ object>#truthValue> <arg@ if: <blk@ {
<msg@ <msg@ <str@ "String with spaces"> <arg@ downcase: (null)> .> <arg@ split: <acc@ <var@ a>#b>> .>
}>> <arg@ else: <blk@ {
<msg@ <str@ "Foobar"> <arg@ print: (null)> .>
}>> .>
2012-05-31 01:33:55.845 tranquil[72250:60b] <cls@ class MyClass < NSObject
<meth@ - <arg@ init: (null)> {
<op@ <var@ self> = <msg@ <var@ super> <arg@ init: (null)> .>>
<op@ <acc@ <var@ self>#ivar> = <str@ "initialized">>
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
volatile int i= 1;
int a = 0;
if(i == 1) {
printf("foo\n");
a=1;
} else {
printf("bar\n");
@className_NSNumber = private unnamed_addr constant [9 x i8] c"NSNumber\00"
@sel_numberWithDouble = private unnamed_addr constant [18 x i8] c"numberWithDouble:\00"
@className_NSString = private unnamed_addr constant [9 x i8] c"NSString\00"
@sel_stringWithUTF8String = private unnamed_addr constant [22 x i8] c"stringWithUTF8String:\00"
@0 = private unnamed_addr constant [7 x i8] c"foobar\00"
@1 = private unnamed_addr constant [7 x i8] c"barfoo\00"
@_NSConcreteGlobalBlock = external global i8**
@2 = private unnamed_addr constant [6 x i8] c"%@:%@\00"
@__block_descriptor_tmp = internal constant { i64, i64, i8*, i8* } { i64 0, i64 0, i8* getelementptr inbounds ([6 x i8]* @2, i32 0, i32 0), i8* null }
@__block_literal_global = internal constant { i8***, i32, i32, i8* ()*, i8* } { i8*** @_NSConcreteGlobalBlock, i32 1342177280, i32 0, i8* ()* @__tq_block_invoke_1, i8* bitcast ({ i64, i64, i8*, i8* }* @__block_descriptor_tmp to i8*) }
%struct.__block_literal_generic = type { i8*, i32, i32, i8*, %struct.__tq_block_descriptor* }
%struct.__tq_block_descriptor = type { i64, i64 }
@_NSConcreteGlobalBlock = external global i8*
@0 = private unnamed_addr constant [6 x i8] c"%@:%@\00"
@__tq_block_descriptor_tmp = internal constant { i64, i64, i8*, i8* } { i64 0, i64 0, i8* getelementptr inbounds ([6 x i8]* @0, i32 0, i32 0), i8* null }
@__tq_block_literal_global = internal constant { i8**, i32, i32, i8* (i8*, i8*)*, i8* } { i8** @_NSConcreteGlobalBlock, i32 1342177280, i32 0, i8* (i8*, i8*)* @__tq_block_invoke_1, i8* bitcast ({ i64, i64, i8*, i8* }* @__tq_block_descriptor_tmp to i8*) }
@className_NSNumber = private unnamed_addr constant [9 x i8] c"NSNumber\00"
@sel_numberWithDouble = private unnamed_addr constant [18 x i8] c"numberWithDouble:\00"
@1 = private unnamed_addr constant [6 x i8] c"%@:%@\00"