Skip to content

Instantly share code, notes, and snippets.

@urigoren
Last active November 28, 2021 12:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urigoren/1c120f721f68ccf732580fd9d0e77b0e to your computer and use it in GitHub Desktop.
Save urigoren/1c120f721f68ccf732580fd9d0e77b0e to your computer and use it in GitHub Desktop.
set splitbelow
nnoremap <F4> :set hlsearch! nohlsearch?<CR>
imap <F4> <C-O><F4>
nnoremap <F2> :let @/="qoXouQoz"<CR>:set invpaste paste?<CR>
set pastetoggle=<F2>
nnoremap <silent> <F3> :let @/ .= '\\|\<'.expand('<cword>').'\>'<cr>n
nnoremap <buffer> <F5> :w<cr>:exec '!/usr/bin/python3' shellescape(@%, 1)<cr>
syntax on
" END/Home work as expected
nnoremap 0 $
nnoremap 9 0
inoremap <C-A> <Home>
inoremap <C-E> <End>
" Indentation with TAB/S-TAB
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set autoindent
nnoremap <Tab> >>_
nnoremap <S-Tab> <<_
inoremap <S-Tab> <C-D>
vnoremap <Tab> >gv
vnoremap <S-Tab> <gv
" Move one line up/down with CTRL+ARROW
noremap <C-up> :call feedkeys( line('.')==1 ? '' : 'ddkP' )<CR>
noremap <C-down> ddp
" Tab open/close with CTRL T/D
noremap <C-T> :Tex<CR>
noremap <C-D> :wincmd c<CR>
" Selection with arrows
nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
imap <S-Up> <Esc>v<Up>
imap <S-Down> <Esc>v<Down>
imap <S-Left> <Esc>v<Left>
imap <S-Right> <Esc>v<Right>
" CTRL+Z is undo
nnoremap <c-z> :u<CR>
inoremap <c-z> <c-o>:u<CR>
set showcmd
set showmatch
set showmode
set cursorline
set nolazyredraw
set encoding=utf8
"Toggle comments with CTRL+/
let s:comment_map = {
\ "c": '\/\/',
\ "cpp": '\/\/',
\ "go": '\/\/',
\ "java": '\/\/',
\ "javascript": '\/\/',
\ "lua": '--',
\ "scala": '\/\/',
\ "php": '\/\/',
\ "python": '#',
\ "ruby": '#',
\ "rust": '\/\/',
\ "sh": '#',
\ "desktop": '#',
\ "fstab": '#',
\ "conf": '#',
\ "profile": '#',
\ "bashrc": '#',
\ "bash_profile": '#',
\ "js": '\/\/',
\ "vim": '"',
\ "tex": '%',
\ }
function! ToggleComment()
if has_key(s:comment_map, &filetype)
let comment_leader = s:comment_map[&filetype]
if getline('.') =~ '^\s*$'
" Skip empty line
return
endif
if getline('.') =~ '^\s*' . comment_leader
" Uncomment the line
execute 'silent s/\v\s*\zs' . comment_leader . '\s*\ze//'
else
" Comment the line
execute 'silent s/\v^(\s*)/\1' . comment_leader . ' /'
endif
else
echo "No comment leader found for filetype"
endif
endfunction
nnoremap <C-_> :call ToggleComment()<CR>
vnoremap <C-_> :call ToggleComment()<CR>
" Run selected code on F6
function s:exec_on_term(lnum1, lnum2)
" get terminal buffer
let g:terminal_buffer = get(g:, 'terminal_buffer', -1)
" open new terminal if it doesn't exist
if g:terminal_buffer == -1 || !bufexists(g:terminal_buffer)
terminal /usr/local/bin/ipython --no-autoindent
let g:terminal_buffer = bufnr('')
wincmd p
" split a new window if terminal buffer hidden
elseif bufwinnr(g:terminal_buffer) == -1
exec 'sbuffer ' . g:terminal_buffer
wincmd p
endif
" join lines with "\<cr>", note the extra "\<cr>" for last line
" send joined lines to terminal.
call term_sendkeys(g:terminal_buffer,
\ join(getline(a:lnum1, a:lnum2)+["",""], "\<cr>"))
endfunction
command! -range ExecOnTerm call s:exec_on_term(<line1>, <line2>)
nnoremap <F6> :ExecOnTerm<cr>
vnoremap <F6> :ExecOnTerm<cr>
" Exit terminal on ESC
tnoremap <ESC> <C-w>:q!<CR>

Vim Modifications:

  1. End and Home keys work as expected:
  2. F2 = paste mode
  3. F3 = search word under cursor
  4. F4 = Highlight mode
  5. F5 = run in python
  6. F6 = Run selection in ipython
  7. Tab and Shift+Tab do indentations
  8. Ctrl+Z = undo
  9. Ctrl+Up/Ctrl+Down = move line up or down
  10. Ctrl+/ = Comment/Uncomment
  11. Ctrl+T/D = open/close a tab
@urigoren
Copy link
Author

urigoren commented Jun 4, 2018

Get this vim config with:

curl -L http://goren.ml/vim > ~/.vimrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment