Skip to content

Instantly share code, notes, and snippets.

@anuvyklack
Last active November 14, 2019 17:33
Show Gist options
  • Save anuvyklack/98cca747f7932163bcb4ec227bd39524 to your computer and use it in GitHub Desktop.
Save anuvyklack/98cca747f7932163bcb4ec227bd39524 to your computer and use it in GitHub Desktop.
[Vim Script]

Получить переменную буфера по номеру окна

getbufvar(winbufnr(window), '&buftype')

Execute command form string epanded with the word under the cursor

noremap <silent> K :execute "vert help ".expand("<cword>")<CR>

If name in list

index(['qf', 'quickfix'], a:name) >= 0

Move line up and down in different regimes

Explanation: The command :m .+1 (which can be abbreviated to :m+) moves the current line to after line number .+1 (current line number + 1). After visually selecting some lines, entering :m '>+1 moves the selected lines to after line number '>+1 (one line after the last selected line; '> is a mark assigned by Vim to identify the selection end). '<,'> will be subsituted between ':' and 'm' automaticaly. The == re-indents the line to suit its new position. For the visual-mode mappings, gv reselects the last visual block and = re-indents that block.

nnoremap <silent> <A-j> :m .+1<CR>==
nnoremap <silent> <A-k> :m .-2<CR>==
inoremap <silent> <A-j> <Esc>:m .+1<CR>==gi
inoremap <silent> <A-k> <Esc>:m .-2<CR>==gi
vnoremap <silent> <A-j> :m '>+1<CR>gv=gv
vnoremap <silent> <A-k> :m '<-2<CR>gv=gv

Function to open command line or terminal from vim

I'v created a function in VIM named OpenCMD(), it used for open command line or terminal in VIM (And cd in the current file path)

func! OpenCMD()
    if has('win32')
        let com = '!cmd /c start cd '. expand('%:p:h')
    else
        let com = '!/usr/bin/gnome-terminal --working-directory=' . expand('%:p:h')
    endif
    silent execute com
endfunc
nmap cmd :call OpenCMD()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment