dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.config/nvim/init.vim

726 lines
22 KiB
VimL

" Important stuff {{{
scriptencoding utf-8 " Set utf-8 as default script encoding
let g:loaded_python_provider=1 " Disable python 2 interface
let g:python_host_skip_check=1 " Skip python 2 host check
let g:python3_host_prog = '/usr/bin/python3'
let g:node_host_prog = '/usr/local/bin/neovim-node-host'
let g:tagbar_ctags_bin = '/usr/bin/ctags'
let python_highlight_all=1 " full python syntax highlighting
" }}}
" Plugins {{{
call plug#begin('~/.config/nvim/plugged')
Plug 'w0rp/ale'
Plug 'othree/yajs.vim', {'for': 'javascript'}
Plug 'othree/es.next.syntax.vim', {'for': 'javascript'}
Plug 'mhartington/nvim-typescript', {'do': './install.sh', 'for': 'typescript'}
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'sheerun/vim-polyglot'
Plug 'liuchengxu/vista.vim'
Plug 'jpalardy/vim-slime'
Plug 'tmsvg/pear-tree'
Plug 'tpope/vim-commentary'
Plug 'honza/vim-snippets'
Plug 'mhartington/oceanic-next'
call plug#end()
" }}}
" Options {{{
set binary
set path+=** " Full tab completion with subfolders and all
set inccommand=nosplit " Live preview of substitutes and other similar commands
set clipboard^=unnamedplus " system clipboard (requires +clipboard)
set fileencoding=utf-8 " The encoding written to file.
set shell=/bin/zsh " Setting shell to zsh
set number " Line numbers on
set noshowmode " Always hide mode
set showtabline=2 " Always Show tabline
set pumheight=12 " Completion window max size
set helpheight=12 " Minimum help window height
set noswapfile " New buffers will be loaded without creating a swapfile
set hidden " Enables to switch between unsaved buffers and keep undo history
set lazyredraw " Don't redraw while executing macros (better performance)
set showmatch " Show matching brackets when text indicator is over them
set matchpairs+=<:> " Add HTML brackets to pair matching
set matchtime=1 " Tenths of a second to show the matching paren
set cpoptions-=m " showmatch will wait 0.5s or until a char is typed
set nojoinspaces " No extra space when joining a line which ends with . ? !
set updatetime=300 " Update time used to create swap file or other things
set synmaxcol=200 " Don't try to syntax highlight minified files
set splitbelow " Splitting a window will put the new window below the current
set splitright " Splitting a window will put the new window right of the current
set notimeout " Time out on key codes but not mappings.
set ignorecase " Ignore case by default
set cursorline " Hightlight the screen line of the cursor
set visualbell " Use visual bell instead of beeping
set scrolloff=5 " Keep this many lines padding when scrolling
set shortmess+=aoOIWcs " Shorten messages and don't show intro
set foldnestmax=10 " Deepest fold is 10 levels
set foldmethod=marker " Markers are used to specify folds.
set foldclose=all " Folds closed by default
set foldlevelstart=10 " Don't auto open folds after this many levels
set selectmode=key " Shift + arrow keys for selecting text
set keymodel=startsel " This one complements the one above it
set signcolumn=yes " Gutter for diagnostics and git status
set tabstop=8 " Number of spaces a <Tab> equals
set shiftwidth=4 " Number of spaces to use in auto(indent)
set softtabstop=4 " While performing editing operations
set shiftround " Round indent to multiple of 'shiftwidth'
set breakindent " Keep indentation
set expandtab
set nosmarttab
set title
set redrawtime=500
set ttimeoutlen=10
set nowritebackup
set completeopt-=preview
set nostartofline
set modeline
set undofile
set undolevels=1000
set undoreload=10000
set undodir=$HOME/.config/nvim/undo
set formatoptions+=nl
set pastetoggle=<F12>
set grepprg=rg\ --vimgrep\ --hidden\ --no-heading
set grepformat=%f:%l:%c:%m,%f:%l:%m
set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png,*.svg " image
set wildignore+=*.manifest " gb
set wildignore+=*.o,*.obj,*.exe,*.dll,*.so,*.out,*.class " compiler
set wildignore+=*.swp,*.swo,*.swn " vim
set wildignore+=*/.git,*/.hg,*/.svn,*/node_modules " vcs
if &diff
set textwidth=80
highlight! link DiffText MatchParen
endif
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
let mapleader="\<SPACE>"
let maplocalleader=','
let formatlistpat='^\s*\(\d\+[\]:.)}\t ]\|[*-][\t ]\)\s*'
let g:polyglot_disabled = ['javascript', 'python']
let g:markdown_fenced_languages = ['vim', 'help']
" }}}
" {{{ Ale
let g:ale_use_global_executables = 1
let g:ale_completion_enabled = 0
let g:ale_linters_explicit = 1
let g:ale_lint_delay = 0
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_insert_leave = 1
let g:ale_fix_on_save = 1
let g:ale_close_preview_on_insert = 1
let g:ale_sign_highlight_linenrs = 1
let g:ale_sign_error = '✖'
let g:ale_sign_warning = '⚠'
let g:ale_sign_info = '●'
let g:ale_set_balloons = 1
let g:ale_virtualtext_cursor = 1
let g:ale_loclist_msg_format = '[%linter%] %s% (code)% [%severity%]'
let g:ale_set_highlights = 1
let g:ale_set_signs = 1
let g:ale_python_mypy_options = '--ignore-missing-imports'
let g:ale_python_pylint_options = '--disable=C'
let g:ale_python_flake8_options = '--ignore=E221'
let g:move_key_modifier = 'N'
let g:ale_linter_aliases = {
\ 'jsx': ['css', 'javascript'],
\ 'vue': ['vue', 'javascript'],
\}
let g:ale_linters = {
\ 'javascript': ['prettier_standard'],
\ 'jsx': ['prettier_standard'],
\ 'typescript': ['tsserver', 'eslint'],
\ 'json': ['prettier'],
\ 'html': ['prettier'],
\ 'css': ['stylelint'],
\ 'scss': ['stylelint'],
\ 'bash': ['shellcheck'],
\ 'sh': ['shellcheck'],
\ 'vim': ['vint'],
\ 'python': ['pyls', 'flake8', 'pylint']
\}
let g:ale_fixers = {
\ 'javascript': ['prettier_standard'],
\ 'jsx': ['prettier_standard'],
\ 'typescript': ['prettier'],
\ 'json': ['prettier'],
\ 'scss': ['stylelint'],
\ 'css': ['stylelint'],
\ 'html': ['prettier'],
\ 'markdown': ['prettier'],
\ 'python': ['autopep8', 'remove_trailing_lines', 'isort', 'yapf']
\}
let g:ale_pattern_options = {
\ '\.min\.js$': {'ale_linters': [], 'ale_fixers': []},
\ '\.min\.css$': {'ale_linters': [], 'ale_fixers': []},
\}
nmap <silent> <F7> <Plug>(ale_previous_wrap)
nmap <silent> <F8> <Plug>(ale_next_wrap)
" }}}
" CoC {{{
let g:coc_global_extensions = ['coc-lists', 'coc-highlight', 'coc-explorer', 'coc-snippets', 'coc-tsserver', 'coc-emmet', 'coc-css', 'coc-html', 'coc-json']
" Explorer
nmap <silent><F5> :CocCommand explorer<CR>
" Config
nnoremap <silent><F6> :CocConfig<CR>
" Lists
nnoremap <silent><F1> :<C-u>CocList -S --ignore-case helptags<CR>
nnoremap <silent><F2> :<C-u>CocList -S --ignore-case files<CR>
nnoremap <silent><F3> :<C-u>CocList --normal buffers<CR>
nnoremap <silent><F4> :<C-u>CocList windows<CR>
" <CR> to confirm completion
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<CR>"
inoremap <silent><expr> <TAB>
\ pumvisible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Snippets
imap <C-j> <Plug>(coc-snippets-expand-jump)
let g:coc_snippet_next = '<tab>'
let g:coc_snippet_prev = '<S-TAB>'
" Python
nnoremap <silent>gp :CocCommand python.execInTerminal<CR>
nnoremap <silent>gr :CocCommand python.startREPL<CR>
"}}}
" Vista {{{
let g:vista#renderer#enable_icon = 1
let g:vista_default_executive = 'ctags'
let g:vista_disable_statusline = 1
let g:vista_sidebar_width = 35
let g:vista_executive_for = {
\ 'javascript': 'coc',
\ 'javascript.jsx': 'coc',
\ 'python': 'ctags',
\ }
nnoremap <silent> <F11> :Vista!!<cr>
" }}}
" JS {{{
let g:vim_jsx_pretty_colorful_config = 1
let g:jsx_ext_required = 1
let g:yats_host_keyword = 1
"}}}
" Colors {{{
set termguicolors
let g:oceanic_next_terminal_italic = 1
colorscheme OceanicNext
function! MyHighlights() abort
highlight Trail ctermbg=red guibg=red
call matchadd('Trail', '\s\+$', 100)
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
endfunction
hi! VertSplit ctermbg=NONE ctermfg=NONE guibg=#080808 guifg=#080808
hi! Comment cterm=italic ctermbg=NONE guibg=NONE
hi! Normal ctermbg=NONE guibg=NONE
hi! NonText ctermbg=NONE guibg=NONE
hi! LineNr guibg=NONE
hi! CursorLineNr ctermbg=236 ctermfg=NONE guibg=#303030
hi! CursorLine ctermbg=236 ctermfg=NONE guibg=#303030
hi! SignColumn ctermbg=NONE guibg=NONE
hi! Folded ctermbg=NONE guibg=NONE
hi! TabLineFill ctermfg=NONE ctermbg=NONE guibg=#080808 guifg=#080808
hi! TablineSel ctermfg=234 ctermbg=4 guibg=#008bbd guifg=#1c1c1c
hi! EndOfBuffer ctermbg=NONE ctermfg=NONE guibg=NONE guifg=#080808
hi! WildMenu ctermfg=228 ctermbg=0 guifg=#ffff00 guibg=#000000
hi! link CocErrorSign WarningMsg
hi! link CocWarningSign Number
hi! link CocInfoSign Type
" }}}
" Statusline {{{
highlight User1 ctermfg=251 ctermbg=NONE guibg=#080808 guifg=#c6c6c6
highlight User2 ctermfg=234 ctermbg=NONE guibg=#f74782 guifg=#1c1c1c
highlight User3 ctermfg=234 ctermbg=4 guibg=#008bb4 guifg=#1c1c1c
highlight User4 ctermfg=234 ctermbg=251 guibg=#c6c6c6 guifg=#1c1c1c
highlight User5 ctermfg=234 ctermbg=4 guibg=#e64eff guifg=#1c1c1c
highlight User6 ctermfg=234 ctermbg=9 guibg=#fbad34 guifg=#1c1c1c
highlight User7 ctermfg=234 ctermbg=251 guibg=#407e4a guifg=#ffffff
let g:modes={
\ 'n' : ['%3*', 'NORMAL'],
\ 'no' : ['%3*', 'NORMAL·OPERATOR PENDING'],
\ 'v' : ['%5*', 'VISUAL'],
\ 'V' : ['%5*', 'V·LINE'],
\ '^V' : ['%5*', 'V·BLOCK'],
\ 's' : ['%7*', 'SELECT'],
\ 'S' : ['%7*', 'S·LINE'],
\ '^S' : ['%7*', 'S·BLOCK'],
\ 'i' : ['%4*', 'INSERT'],
\ 'R' : ['%2*', 'REPLACE'],
\ 'Rv' : ['%2*', 'V·REPLACE'],
\ 'c' : ['%6*', 'COMMAND'],
\ 'cv' : ['%6*', 'VIM EX'],
\ 'ce' : ['%6*', 'EX'],
\ 'r' : ['%1*', 'PROMPT'],
\ 'rm' : ['%1*', 'MORE'],
\ 'r?' : ['%1*', 'CONFIRM'],
\ '!' : ['%*1', 'SHELL'],
\ 't' : ['%*1', 'TERMINAL']
\}
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf(
\ ' ⚠ :%d ✖ :%d ',
\ l:all_non_errors,
\ l:all_errors
\)
endfunction
function! ModeColor() abort
return get(g:modes, mode(), '%*')[0]
endfunction
function! CurrentMode() abort
return ' ' . get(g:modes, mode(), '-')[1] . ' '
endfunction
function! LinePasteMode()
let paste_status = &paste
if paste_status == 1
return ' paste '
else
return ''
endif
endfunction
function! Statusline()
let b:status=''
let b:status.=ModeColor()
let b:status.=CurrentMode()
let b:status.=LinePasteMode()
let b:status.='%1* '
let b:status.='%= '
let b:status.=coc#status()
let b:status.=' %6*'
let b:status.=LinterStatus()
let b:status.='%3* %p%% %c '
return b:status
endfunction
set statusline=%!Statusline()
" }}}
" Tabline {{{
function! Tabline()
let s = ''
for i in range(tabpagenr('$'))
let tab = i + 1
let winnr = tabpagewinnr(tab)
let buflist = tabpagebuflist(tab)
let bufnr = buflist[winnr - 1]
let bufname = bufname(bufnr)
let bufmodified = getbufvar(bufnr, '&mod')
let s .= '%' . tab . 'T'
let s .= (tab == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
let s .= ' ' . tab .':'
let s .= (bufname !=? '' ? fnamemodify(bufname, ':t') . ' ' : '[No Name] ')
if bufmodified
let s .= ' + '
endif
endfor
let s .= '%#TabLineFill#'
if (exists('g:tablineclosebutton'))
let s .= '%=%999XX'
endif
return s
endfunction
set tabline=%!Tabline()
" }}}
" AutoCommands {{{
if !exists('autocommands_loaded') && has('autocmd')
let autocommands_loaded = 1
" Plug updates itself automatically
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
aug Plugged
au VimEnter * PlugInstall --sync | source $MYVIMRC
aug END
endif
function! PopOutOfInsertMode()
if v:insertmode
call feedkeys("\<C-\>\<C-n>")
endif
endfunction
function! Relativize(v)
if &number
let &relativenumber = a:v
endif
endfunction
function! LocalStatusLine()
let b:status = '%#error#[HELP]%*'
return b:status
endfunction
aug relativize
au BufWinEnter,FocusGained,InsertLeave,WinEnter * call Relativize(1)
au BufWinLeave,FocusLost,InsertEnter,WinLeave * call Relativize(0)
aug END
aug status_line
au FileType help setlocal statusline=%!LocalStatusLine()
au FileType man setlocal statusline=%!LocalStatusLine()
aug END
aug on_save
" Delete whitespace on :w
au BufWritePre * :%s/\s\+$//e
au BufWritePost *xresources !xrdb %
au BufWritePost *sxhkdrc !pkill -USR1 sxhkd
au QuitPre * if empty(&buftype) | lclose | endif
aug END
aug term_stuff
au TermOpen * setlocal nonumber norelativenumber
au TermOpen * setlocal laststatus=0
au TermOpen * setlocal nocursorline
au TermOpen * setlocal signcolumn=no
au TermOpen * setlocal noshowmode
au TermOpen * setlocal noruler
aug END
aug miscs
" Highlight symbol under cursor on CursorHold
au CursorHold * silent call CocActionAsync('highlight')
au CursorHold * call CocActionAsync('doHover')
au User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
au ColorScheme * call MyHighlights()
aug END
aug inserts
au InsertEnter * setlocal nocursorline
au InsertLeave * setlocal cursorline
au InsertLeave * setlocal nopaste
au InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif
au FocusLost,TabLeave * call PopOutOfInsertMode()
aug END
aug skeletons
au BufNewFile *.py 0r ~/.config/nvim/templates/py.skeleton
au BufNewFile *.sh 0r ~/.config/nvim/templates/sh.skeleton
aug END
aug file_types
au FileType * setl formatoptions-=cro
au FileType typescript,json setl formatexpr=CocAction('formatSelected')
au FileType json syntax match Comment +\/\/.\+$+
aug END
endif
" }}}
" REPL {{{
let g:slime_target = 'neovim'
let g:slime_python_ipython = 1
let g:my_active_terminal_job_id = -1
function! LaunchTerminal() range
silent exe "normal! :12split\n"
silent exe "normal! :terminal\n"
call SetActiveTerminalJobID()
endfunction
function! LaunchSC() range abort
silent exe "normal! :tabnew\n"
silent exe "normal! :terminal\n"
call SetActiveTerminalJobID()
call jobsend(g:my_active_terminal_job_id, "scsynth -u 57110\r")
sleep 2200ms
silent exe "normal! G"
silent exe "normal! :vsplit\n"
silent exe "normal! :terminal\n"
call SetActiveTerminalJobID()
call jobsend(g:my_active_terminal_job_id, "sclang -D ~/Music/LiveCoding/foxdot.scd\r")
silent exe "normal! :tabprev\n"
silent exe "normal! <cr>\n"
sleep 2200ms
silent exe 'normal! G'
endfunction
function! LaunchIpython() range abort
call LaunchTerminal()
call jobsend(g:my_active_terminal_job_id, "ipython\r")
sleep 2200ms
silent exe "normal! G"
endfunction
function! LaunchFoxDot() range abort
call LaunchTerminal()
call jobsend(g:my_active_terminal_job_id, "ipython\r")
sleep 2200ms
call jobsend(g:my_active_terminal_job_id, "from FoxDot import *\r")
silent exe 'normal! G'
endfunction
function! SetActiveTerminalJobID()
let g:my_active_terminal_job_id = b:terminal_job_id
echom "Active terminal job ID set to " . g:my_active_terminal_job_id
endfunction
map <silent> <Leader>xi :call LaunchIpython()<CR>
map <silent> <Leader>xs :call LaunchSC()<CR>
map <silent> <Leader>xd :call LaunchFoxDot()<CR>
map <silent> <Leader>xf :set filetype=foxdot<CR>
"}}}
" Vim-Tmux Navigator {{{
" Intelligently navigate tmux panes and Vim splits using the same keys.
" See https://sunaku.github.io/tmux-select-pane.html for documentation.
let progname = substitute($VIM, '.*[/\\]', '', '')
set title titlestring=%{progname}\ %f\ +%l\ #%{tabpagenr()}.%{winnr()}
if &term =~? '^screen' && !has('nvim') | exe "set t_ts=\e]2; t_fs=\7" | endif
"}}}
"Mappings {{{
"Normal {{{
" Plug
nnoremap <leader>pu :PlugUpdate<CR>
" Ñ master race
nnoremap ñ ;
nnoremap Ñ ,
" Rearrange Splits
nnoremap <silent> <leader> <Left> <C-W>H
nnoremap <silent> <leader> <Right> <C-w>L
nnoremap <silent> <leader> <Up> <C-W>K
nnoremap <silent> <leader> <Down> <C-W>J
" Resize splits
nnoremap <silent> <Left> :vertical resize -2<CR>
nnoremap <silent> <Right> :vertical resize +2<CR>
nnoremap <silent> <Up> :resize -1<CR>
nnoremap <silent> <Down> :resize +1<CR>
" Maximize current split vertically
nnoremap <silent> <leader>z <C-W><C-_>
" Make all splits equal size vertically
nnoremap <silent> <leader>Z <C-W><C-=>
" Edit and source config file
nnoremap <silent> <leader>ev :vsplit $MYVIMRC<CR>
nnoremap <silent> <leader>sv :source $MYVIMRC<CR>
" Fast saves
nnoremap <silent> <leader>w :w!<CR>
" Fast closes
nnoremap <silent> <leader>b :bdelete<CR>
" Fast exits
nnoremap <silent> <leader>q :q!<CR>
nnoremap <silent> <leader>Q :qa!<CR>
" Fast leave insert mode
cnoremap jk <C-c>
" Fast beginning and end of document
nnoremap <Bar> gg
nnoremap ¿ G
" Fast message checking
nnoremap <silent> <leader>m :messsages<CR>
" Splits
nnoremap <silent> <leader>T :call LaunchTerminal()<CR>
nnoremap <silent> <leader>s :split<CR>
nnoremap <silent> <leader>v :vsplit<CR>
nnoremap <silent> <leader>nv :vnew<CR>
nnoremap <silent> <leader>ns :new<CR>
" My vim wants to enter all the time, enter all the time
nnoremap <silent> <CR> i<CR><ESC>
" Quote words under cursor
nnoremap <leader>" viW<esc>a"<esc>gvo<esc>i"<esc>gvo<esc>3l
nnoremap <leader>' viW<esc>a'<esc>gvo<esc>i'<esc>gvo<esc>3l
" Move a line of text using Shift+[jk]
nnoremap <silent> <S-j> mz:m+<cr>`z
nnoremap <silent> <S-k> mz:m-2<cr>`z
" Unhighlight search terms
nnoremap <silent> <leader><space> :noh<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
" j = gj :: k = gk while preserving numbered jumps ie. 12j or 30k
nnoremap <buffer><silent><expr>j v:count ? 'j' : 'gj'
nnoremap <buffer><silent><expr>k v:count ? 'k' : 'gk'
" Line movements
noremap <silent> <Home> g<Home>
noremap <silent> <End> g<End>
nnoremap Y 0y$
nnoremap <leader>y y$
" Tab movement
nnoremap tn :tabnew<cr>
nnoremap th :tabfirst<cr>
nnoremap tl :tablast<cr>
nnoremap tx :tabclose<cr>
" Center view on search result
nnoremap n nzz
nnoremap N Nzz
nnoremap * *zz
nnoremap # #zz
nnoremap g* g*zz
nnoremap g# g#zz
" What about the Q
nnoremap Q <nop>
map q <nop>
" Shift butterfinger
:command! WQ wq
:command! Wq wq
:command! Wqa wqa
:command! Wa wa
:command! WA wa
:command! W w
:command! Q q
:command! Qa qa
:command! QA qa
"}}}
"Insert {{{
inoremap jk <esc>
inoremap kj <esc>
" Ensure that ctrl+u in insert mode can be reversed
" http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
" Deedee
inoremap <c-d> <esc>ddi
" Line movements
inoremap <silent> <Home> <C-o>g<Home>
inoremap <silent> <End> <C-o>g<End>
" Alt to switch windows
inoremap <A-h> <Esc><C-w>h
inoremap <A-j> <Esc><C-w>j
inoremap <A-k> <Esc><C-w>k
inoremap <A-l> <Esc><C-w>l
"}}}
"Visual {{{
" Fast beginning and end of document
vnoremap ¿ G
vnoremap <Bar> gg
" Visual mode pressing # searches for the current selection
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
" Move a line of text using Shift+[jk]
vnoremap <S-j> :m'>+<cr>`<my`>mzgv`yo`z
vnoremap <S-k> :m'<-2<cr>`>my`<mzgv`yo`z
" j = gj :: k = gk while preserving numbered jumps ie. 12j or 30k
vnoremap <buffer><silent><expr>j v:count ? 'j' : 'gj'
vnoremap <buffer><silent><expr>k v:count ? 'k' : 'gk'
" Line movements
vnoremap $ $h
" Fix indentation without leaving visual mode
vnoremap > >gv
vnoremap < <gv
" Delete current visual selection and dump in black hole buffer before pasting
" Used when you want to paste over something without it getting copied to
" Vim's default buffer
vnoremap <leader>p "_dP
"}}}
"Terminal {{{
" Terminal movement
tnoremap <Esc> <C-\><C-n>
tnoremap <M-h> <C-\><C-n><C-w>h
tnoremap <M-j> <C-\><C-n><C-w>j
tnoremap <M-k> <C-\><C-n><C-w>k
tnoremap <M-l> <C-\><C-n><C-w>l
"}}}
"}}}
" Functions {{{
function! CmdLine(str)
call feedkeys(':' . a:str)
endfunction
" vp doesn't replace paste buffer
function! RestoreRegister()
let @" = s:restore_reg
return ''
endfunction
function! s:Repl()
let s:restore_reg = @"
return "p@=RestoreRegister()\<cr>"
endfunction
vmap <silent> <expr> p <sid>Repl()
" global replace
vnoremap <Leader>sw "hy
\ :let b:sub = input('global replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ let b:rep = substitute(getreg('h'), '/', '\\/', 'g') <Bar>
\ execute '%s/'.b:rep."/".b:sub.'/g' <Bar>
\ unlet b:sub b:rep <Bar>
\ endif <CR>
nnoremap <Leader>sw
\ :let b:sub = input('global replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ execute "%s/<C-r><C-w>/".b:sub.'/g' <Bar>
\ unlet b:sub <Bar>
\ endif <CR>
" prompt before each replace
vnoremap <Leader>cw "hy
\ :let b:sub = input('interactive replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ let b:rep = substitute(getreg('h'), '/', '\\/', 'g') <Bar>
\ execute '%s/'.b:rep.'/'.b:sub.'/gc' <Bar>
\ unlet b:sub b:rep <Bar>
\ endif <CR>
nnoremap <Leader>cw
\ :let b:sub = input('interactive replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ execute "%s/<C-r><C-w>/".b:sub.'/gc' <Bar>
\ unlet b:sub <Bar>
\ endif <CR>
" local keyword jump
nnoremap <Leader>fw
\ [I:let b:jump = input('Go To: ') <Bar>
\ if b:jump !=? '' <Bar>
\ execute "normal! ".b:jump."[\t" <Bar>
\ unlet b:jump <Bar>
\ endif <CR><Paste>
" }}}
" vim:foldmethod=marker:foldlevel=0