- 少し整理/追加したのでごちゃつく前に記録
Enum.map()
以外も追加したいような、きりがないような、悩ましいところ
- VSnipを使用
現状
.vsnip/elixir.json
{
"chain": {
"prefix": "c",
"body": [
"|> "
]
},
"def": {
"prefix": "def",
"body": [
"def $1 do",
" $0",
"end"
]
},
"def short": {
"prefix": "defl",
"body": [
"def $1, do: $2"
]
},
"defp": {
"prefix": "defp",
"body": [
"defp $1 do",
" $0",
"end"
]
},
"defp short": {
"prefix": "defpl",
"body": [
"defp $1, do: $2"
]
},
"defdelegate": {
"prefix": "defd",
"body": [
"defdelegate $1, to: $2"
]
},
"defn": {
"prefix": "defn",
"body": [
"defn $1 do",
" $0",
"end"
]
},
"@moduledoc": {
"prefix": "@mod",
"body": [
"@moduledoc \"\"\"",
"$0",
"\"\"\""
]
},
"@doc": {
"prefix": "@doc",
"body": [
"@doc \"\"\"",
"$0",
"\"\"\""
]
},
"doc examples": {
"prefix": "doce",
"body": [
"## Examples",
"",
" iex> $1"
]
},
"io inspect": {
"prefix": "ioi",
"body": [
"IO.inspect($1, label: \"${0:\\n\\n}\")"
]
},
"here for io label": {
"prefix": "here",
"body": [
"\\n#{inspect __ENV__.context_modules}#{inspect __ENV__.function}\\n"
]
},
"function": {
"prefix": "f",
"body": [
"fn $1 do",
" $0",
"end"
]
},
"function short": {
"prefix": "fl",
"body": [
"& &1"
]
},
"then function": {
"prefix": "ct",
"body": [
"|> then(fn $1 do",
" $0",
"end)"
]
},
"then function short": {
"prefix": "ctl",
"body": [
"|> then(& $0)"
]
},
"then with io inspection": {
"prefix": "ctioi",
"body": [
"|> then(fn item -> IO.inspect(item, label: \"${0:\\n\\n}\"); item end)"
]
},
"Enum start": {
"prefix": "e",
"body": [
"Enum.$1($0)"
]
},
"Enum start with chain": {
"prefix": "ce",
"body": [
"|> Enum.$1($0)"
]
},
"Enum.map with chain": {
"prefix": "cem",
"body": [
"|> Enum.map(& &1$0)"
]
},
"Map start": {
"prefix": "m",
"body": [
"Map.$1($0)"
]
},
"Map start with chain": {
"prefix": "cm",
"body": [
"|> Map.$1($0)"
]
},
"List start": {
"prefix": "l",
"body": [
"List$1"
]
},
"List start with chain": {
"prefix": "cl",
"body": [
"|> List.$1($0)"
]
},
"Keyword start": {
"prefix": "k",
"body": [
"Keyword.$1($0)"
]
},
"Keyword start with chain": {
"prefix": "ck",
"body": [
"|> Keyword.$1($0)"
]
},
"Flow map chain": {
"prefix": "flow",
"body": [
"|> Flow.from_enumerable()",
"|> Flow.map($0)",
"|> Enum.to_list()"
]
},
"defmacro using": {
"prefix": "defmu",
"body": [
"defmacro __using__(which) when is_atom(which) do",
" apply(__MODULE__, which, [])",
"end"
]
},
"live view socket.assigns": {
"prefix": "sa",
"body": [
"socket.assigns."
]
},
"live view assign": {
"prefix": "as",
"body": [
"assign($0)"
]
},
"live view handle_event": {
"prefix": "defhe",
"body": [
"@impl true",
"def handle_event(\"$1\", ${2:params}, socket) do",
" $3",
"end"
]
},
"live view handle_info": {
"prefix": "defhi",
"body": [
"@impl true",
"def handle_info({:$1}, socket) do",
" $2",
"end"
]
}
}
参考
vimrcの設定は下記のような感じ
" vim-vsnip
" samples: https://github.com/rafamadriz/friendly-snippets/tree/main/snippets
imap <expr> <C-l> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-l>'
smap <expr> <C-l> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-l>'
imap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
smap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'