Last active
October 30, 2017 07:38
-
-
Save p1xelHer0/ba13d5830be75c85821c59a8abf7025a to your computer and use it in GitHub Desktop.
small vim tips extracted from my dotfiles: https://github.com/p1xelHer0/dotfiles/tree/master/conf/neovim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" I work on both Linux and macOS, so some settings differ on those system | |
function! g:IsMacOS() | |
if has('unix') | |
let s:uname = system('uname') | |
if s:uname ==? "Darwin\n" | |
return 1 | |
else | |
return 0 | |
endif | |
endif | |
endfunction | |
" one example might be clipboard, use the function like this: | |
if IsMacOS() | |
set clipboard=unnamed " normal OS clipboard interaction | |
else " use xsel on Linux | |
set clipboard+=unnamedplus | |
endif | |
" your .vimrc will now work on both Linux and macOS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" make your Vim colors match colors from .gitconfig | |
" store colors from Git in variable | |
let g:GitAddColor = system('git config --list | grep added | grep -o -E "[0-8]"') | |
let g:GitChangeColor = system('git config --list | grep changed | grep -o -E "[0-8]"') | |
let g:GitUntrackedColor = system('git config --list | grep untracked | grep -o -E "[0-8]"') | |
" you can now use your Git colors like the following: | |
execute 'highlight DiffAdd cterm=reverse ctermfg=' . g:GitAddColor | |
execute 'highlight DiffChange cterm=reverse ctermfg=' . g:GitChangeColor | |
execute 'highlight DiffDelete cterm=reverse ctermfg=' . g:GitUntrackedColor | |
" now your DiffColors in Vim will match your colors defined in .gitconfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" store relative line number jumps in the jumplist if they exceed a threshold | |
" make j and k use strict linewise movements when using `set breakindent` | |
nnoremap <expr> j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj' | |
nnoremap <expr> k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk' | |
" you can now navigate each line even with `breakindent` on, | |
" AND | |
" when using a prefix with j/k, such as `10j` you can use <C-o> to jump back |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" f10 prints the current highlight rules for cursor selection | |
nnoremap <F10> :echo 'hi<' . synIDattr(synID(line('.'),col('.'),1),'name') . '> trans<' | |
\ . synIDattr(synID(line('.'),col('.'),0),'name') . '> lo<' | |
\ . synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name') . '>'<CR> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" configs split up according to functionality | |
let s:configs = [ | |
\ 'plugins', | |
\ 'settings', | |
\ 'settings.plugins', | |
\ 'mappings', | |
\ 'mappings.plugins', | |
\ 'ui', | |
\ 'ui.statusline', | |
\ 'ui.plugins', | |
\ 'commands', | |
\ ] | |
" path where configs are stored | |
let s:NEOVIM_CONFIG = '$HOME/dotfiles/conf/neovim/' | |
" load all configs | |
for s:config in s:configs | |
let s:configPath = s:NEOVIM_CONFIG . s:config . '.vim' | |
execute 'source ' . fnameescape(s:configPath) | |
endfor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" auto install plug if not found | |
" configure this to match your own path | |
if empty(glob('$HOME/.config/nvim/autoload/plug.vim')) | |
silent !curl -fLo "$HOME/.config//nvim/autoload/plug.vim" --create-dirs | |
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
augroup PLUG | |
autocmd! | |
autocmd VimEnter * PlugInstall | |
augroup END | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment