diff --git a/vim/ftplugin/javascript.vim b/vim/ftplugin/javascript.vim new file mode 100644 index 0000000..64dccd4 --- /dev/null +++ b/vim/ftplugin/javascript.vim @@ -0,0 +1,67 @@ +" make Vim recognize ES6 import statements +let &l:include = 'from\|require' + +" allow Vim to parse path aliases such as ~/components or @/components +" which are common in Vue projects +setlocal isfname+=@-@ +setlocal suffixesadd+=.vue +let &l:includeexpr = "path#resolve_alias(['~', '@'], ['src', 'app'], v:fname)" + +" make Vim use ES6 export statements as define statements +let &l:define = '\v(export\s+(default\s+)?)?(var|let|const|(async\s+)?function|class)|export\s+' + +setlocal textwidth=80 + +" define convenience sniplets +let s:snippets_map={ + \ "log": "console.log(", + \ "warn": "console.warn(", + \ "json": "JSON.stringify", + \ "jlog": "console.log(JSON.stringify(, null, 2))\2F,", + \ "fn": "() => {}", + \ "if": "if () {\\k\f)", + \ "ifelse": "if () {\\j else {\\3k\f)", + \ "try": "try {\\j catch (error) {\\{\", + \ "tryf": "try {\\j catch (error) {\\j finally {\\2{\", + \ "pobj": "PropTypes.object", + \ "pfn": "PropTypes.func", + \ "parr": "PropTypes.arrayOf(", + \ "pstr": "PropTypes.string", + \ "pbool": "PropTypes.bool", + \ "pshape": "PropTypes.shape({", + \ "pnum": "PropTypes.number", + \ "pany": "PropTypes.any", + \ "pnode": "PropTypes.node", + \ "pone": "PropTypes.oneOf([", + \ "ptypes": "static propTypes = {", + \ "defprops": "static defaultProps = {", + \ "ctypes": "static contextTypes = {", + \ "constructor": "constructor(props) { +super(props);", + \ "cwm": "componentWillMount() {", + \ "cdm": "componentDidMount() {", + \ "scu": "shouldComponentUpdate(nextProps, nextState) {", + \ "cwrp": "componentWillReceiveProps(nextProps) {", + \ "cwu": "componentWillUpdate() {", + \ "cdu": "componentDidUpdate() {", + \ "cwum": "componentWillUnmount() {", + \ } + +for [s:pattern, s:expansion] in items(s:snippets_map) + execute "ISnipletBuffer" s:pattern s:expansion +endfor + +CSnipletBuffer json JSON.stringify +CSnipletBuffer warn console.warn +CSnipletBuffer log console.log + +" define convenience map for destructuring +inoremap xx ;Bconst {} = F} +inoremap xi ';B'import {} from F} + +" define convenience map for passing down handler props +inoremap xp "zyiwz={} + \:keeppatterns s/handle/on + +" allow filename completion with import * from ../ +call cwd#ChangeOnInsert() diff --git a/vim/ftplugin/typescript-react.vim b/vim/ftplugin/typescript-react.vim new file mode 100644 index 0000000..c23ec13 --- /dev/null +++ b/vim/ftplugin/typescript-react.vim @@ -0,0 +1 @@ +runtime! ftplugin/typescript.vim diff --git a/vim/ftplugin/typescript.vim b/vim/ftplugin/typescript.vim new file mode 100644 index 0000000..da4b1e8 --- /dev/null +++ b/vim/ftplugin/typescript.vim @@ -0,0 +1,21 @@ +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +let s:cpo_save = &cpo +set cpo-=C + +compiler typescript +setlocal commentstring=//\ %s + +" Set 'formatoptions' to break comment lines but not other lines, +" " and insert the comment leader when hitting or using "o". +setlocal formatoptions-=t formatoptions+=croql + +setlocal suffixesadd+=.ts,.tsx + +let b:undo_ftplugin = "setl fo< ofu< com< cms<" + +let &cpo = s:cpo_save +unlet s:cpo_save