- End and Home keys work as expected:
- F2 = paste mode
- F3 = search word under cursor
- F4 = Highlight mode
- F5 = run in python
- F6 = Run selection in ipython
- Tab and Shift+Tab do indentations
- Ctrl+Z = undo
- Ctrl+Up/Ctrl+Down = move line up or down
- Ctrl+/ = Comment/Uncomment
- Ctrl+T/D = open/close a tab
Last active
November 28, 2021 12:27
-
-
Save urigoren/1c120f721f68ccf732580fd9d0e77b0e to your computer and use it in GitHub Desktop.
This file contains 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
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get this vim config with:
curl -L http://goren.ml/vim > ~/.vimrc