Skip to content

Instantly share code, notes, and snippets.

@rexagod
Created December 12, 2020 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexagod/2d923eeb3dfe26e8f90cc96d5d9d36bd to your computer and use it in GitHub Desktop.
Save rexagod/2d923eeb3dfe26e8f90cc96d5d9d36bd to your computer and use it in GitHub Desktop.
" Mappings based on autocommands.
" Autocommands can also be chained.
" au Filetype javascript nn <buffer> <M-a> :!node %<cr>
" <buffer> points to the script the com was declared in
" nn <buffer> <leader>l :echom expand('%')<cr>
" OPERATOR-PENDING MAPPING
" :normal hides the effect of the preceding operator
" onoremap in( :<c-u>normal! f(vi(<cr>
" onoremap in( :<c-u>normal! f{vi}<cr>
" normal does not recognise special symbols like <cr>
" hence we use execute
" ono ih :<c-u>execute "normal! ?^==\\+$\r:noh\rkvg_"<cr>
" see pattern-overview
" file, dirty, row, col, pos
" select first, then apply
" %-0{minwid}.{maxwid}{item}
" set statusline=[%-4l]
" In visual mode, a simple "S" with an argument wraps the selection
" A t is a pair of HTML or XML tags. See |tag-blocks| for details. Remember
" that you can specify a numerical argument if you want to get to a tag other
" than the innermost one.
" <div>Yo!</div> -> Yo!
" set statusline=%<%f\ %m%=%y\ %r%{FugitiveStatusline()}\ [%l,%c%V]\ %3p%{nr2char(37)}
" let w='abc'
" let w=w " reassign like so
" echo w
" echo &textwidth " access options
" <Ctrl+[register name]> to paste it's value (in cmdline or insert mode)
" @/"+[register name]
" to add to a writable register, say @w, do let @W=@a (uppercase == +=)
" "+ is the clipboard register
" "0 stores latest yank, others have deleted text
" "/? search registers
" Use & to refer already existing options
" set -> &g:, setlocal -> &l:
" internal-variables
" Commands (let ...), Expressions(5+5), and Literals(variables -> echo ...)
" let g:rexagod = 1 " eg exists(g:rexagod)
" let b:rexagod = 2
" let &b:number=0 " eg exists(&g:number)
" separate commands in single line using: <bar> or |, eg., :echom "foo" | echom "bar"
" we can use "x after the command to store that in register x
" wont work for "0..." or "..."
" if "1-ty-one"
" echo 11
" endif
" if 0
" echo 0
" elseif "falsy"
" echo "nop"
" else
" echo "finally"
" endif
" ". contains the last inserted text
" if 10 > 1
" echo ">"
" endif
" gF(number preceeded by filename) or just gf to open file under cursor, try: ~/.vimrc
" if 10 == 11
" echo "here"
" elseif 10 == 10
" echo "or here"
" endif
" == depends upon user settings
" set ignorecase
" if "foo" == "FOO"
" echom "vim is case insensitive"
" elseif "foo" == "foo"
" echom "vim is case sensitive"
" endif
" set noignorecase
" if "foo" == "FOO"
" echom "vim is case insensitive"
" elseif "foo" == "foo"
" echom "vim is case sensitive"
" endif
" ==# -> strict case-sensitive
" ==? -> strict case-insensitive
" see expr4
" function Say()
" echo "hi"
" endfunction
" call Say()
" " reassignment
" function! Say()
" return 2
" endfunction
" echom Say()
" | -> cmdline, <bar> -> mappings
" function Nop()
" " returns 0 as implicit value
" endfunction
" function Varg2(foo, ...)
" echom a:foo
" " all these refer the varargs
" echom a:0
" echom a:1
" echo a:000
" endfunction
" call Varg2("a", "b", "c")
" function AssignGood(foo)
" let foo_tmp = a:foo
" let foo_tmp = "Yep"
" echom foo_tmp
" endfunction
" call AssignGood("test")
" function Assign(foo)
" let a:foo = "Nope" " cannot assign directly to args
" echom a:foo
" endfunction
" call Assign("test")
" let n=17
" exe "echo 0".n
" echo 0x15
" echo 015
" echo 15
" echo 2.43e7
" echo 2.43e6
" echo 2e3 " error
" echo 2.0e3 " works
" echo 2 * 2.0
" echo 3/2.0
" + is only for numbers. Use . for concatentations.
" echo "3 x" + "4 y"
" echo 10 + "10.10"
" echo "x" + "y"
" works as expected since . operator is used
" not works with floats, though, since >1 decimals cause ambiguity
" echo 10 . "foo"
" let @B="z"
" Literal Strings: '...'
" ''(=') is the only sequence with a special meaning inside '...' while all others
" are left as-is.
" echo '\n\\'''
" echo strlen("foo")
" echo len("bar")
" echo split("foo bar baz")
" echo split("foo,bar,baz",",")
" echo join(["FOO","BAR","BAZ"])
" echo tolower(["FOO"][0])
" echo toupper(["FOO"][0])
" help string-functions
" echo sha256("rexagod")
" normal does not parse special char sequences like <esc>,
" hence, use execute
" exe "normal[!->nn] ggvG$\<esc>oi"
" \ escape sequences only work inside "", not ''
" hence, special vim-sequences such as <cr> need to be inside
" "" inorder to be escaped
" help g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment