Vimscript: Sample codes for command completions

Sample Code

 

" Sample functions {{{
function! Varg(foo)
    "echom a:0
    "echom a:1
    "echom a:2
    echom a:foo
    let cmd_str = "git ls-remote ssh://wall.lge.com/" . a:foo . " | head -n 10"
    let r = system(cmd_str)
    !echo r
endfunction

function! Vargs2(foo, ...)
    "echom a:foo
    "echom a:0
    " echom a:1
    echo a:0
endfunction

function! Assign(foo)
    " let a:foo = "Nope"
    let foo_tmp = a:foo
    let foo_tmp = "Yep"
    echom a:foo
    endfunction
" }}}

com! -complete=custom,ListUserstwo -nargs=1 Sunjoo2 call Varg("")
fun! ListUserstwo(A,L,P)
    return "starfish/build-starfish\nwebos-pro/meta-lg-webos"
endfun

Sunjoo2: Command name

call Varg(“”): Vim command triggered when calling a command

ListUserstwo: Function that returns a list of strings for parameter completion

Advertisements

Vim shortcuts

Autocomplete

  • Insert file/directory path at ‘Insert mode’ ( Link )
    • In order to insert a relative path with a current directory
      • Just ‘Ctrl-x  + Ctrl -f
    • In order to insert an absolute path
      • Insert a slash ‘/’
      • Ctrl-x  + Ctrl -f

Define VIM shorcuts for ‘Tab’-related actions

Reference: https://superuser.com/a/622114

if has("gui_macvim")
" Press Ctrl-Tab to switch between open tabs (like browser tabs) to
" the right side. Ctrl-Shift-Tab goes the other way.
noremap  :tabnext
noremap  :tabprev

" New Tab
noremap  :tabnew
" Switch to specific tab numbers with Command-number
noremap  :tabn 1
noremap  :tabn 2
noremap  :tabn 3
noremap  :tabn 4
noremap  :tabn 5
noremap  :tabn 6
noremap  :tabn 7
noremap  :tabn 8
noremap  :tabn 9
" Command-0 goes to the last tab
noremap  :tablast
endif

Install vim 8.1.390 on OSX 10.13.4

 

  1. Download a release tar ball version   that you want to download
  2. Determine an install location
    • /usr/local/Cellar/vim/8.1.0390
  3. Run a configuration script
    • ./configure --prefix=/usr/local --mandir=/usr/local/Cellar/vim/8.1.0390/share/man --enable-multibyte --with-tlib=ncurses --enable-cscope --with-compiledby=Homebrew --enable-perlinterp --enable-pythoninterp --enable-rubyinterp --enable-gui=no --without-x --srcdir=. --cache-file=auto/config.cache
  4. Run ‘make
    • make install prefix=/usr/local/Cellar/vim/8.1.0390 STRIP=true
  5. Set VIMRUNTIME variable
    • export VIMRUNTIME=/usr/local/Cellar/vim/8.1.0390/share/vim/vim81
  6. Set PATH variable
    • export PATH=/usr/local/Cellar/vim/8.1.0390/bin:${PATH}