GithubHelp home page GithubHelp logo

reconquest / vim-autosurround Goto Github PK

View Code? Open in Web Editor NEW
54.0 6.0 4.0 44 KB

Automatically insert pairs (brackets, quotes) where they are supposed to be

Python 54.85% Shell 40.31% Vim Script 4.83%
vim pair surround braces

vim-autosurround's Introduction

Plugin will automatically add enclosing ) (or any other) at appropriate place to be.

gif

Currently, following cases are supported:

  • adding pair after call-like construction:

    |something()        type: test( ->
    test(|something())
    
  • adding pair after string:

    |"blah"       type: test( ->
    test(|"blah")
    
  • adding pair after argument:

    something(|arg1, arg2)        type: test( ->
    something(test(|arg1), arg2)
    
    something(arg1, |arg2)        type: test( ->
    something(arg1, test(arg2))
    
  • adding pairs in conditionals:

    if |blah != nil       type test( ->
    if test(blah) != nil
    
  • autocorrection:

    something(|arg1, arg2)        type: test( ->
    something(test(|arg1), arg2)  move cursor after last ) and type ) ->
    something(test(arg1), arg2)|
    something(test(arg1, arg2))|
    

Installation & Usage

Plug 'vim-autosurround'

Plugin provides only python API.

Extension

Plugin provides API, which can be used to extend surround logic:

  • index = autosurround.register_finder(callback), callback is a function of one argument cursor, which is vim.current.window.cursor.

    callback should return tuple (line, column) with position, which will be used for inserting pair character or None, if callback is not able to find position.

    index can be used for unregister_finder(index).

  • autosurround.unregister_finder(index) will remove previously added callback.

vim-autosurround's People

Contributors

kovetskiy avatar mbaraa avatar seletskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vim-autosurround's Issues

Nvim + golang

There's some problem in nvim.

Reproduce:

  1. Create new file main.go.
  2. Start typing "func main(".

Result:

Error detected while processing function AutoSurround..provider#python#Call:
line   18:
TypeError("unhashable type: 'list'",)
Traceback (most recent call last):

  File "/usr/local/lib/python2.7/site-packages/neovim/msgpack_rpc/session.py", line 177, in handler
    rv = self._request_cb(name, args)
  File "/usr/local/lib/python2.7/site-packages/neovim/api/common.py", line 237, in filter_request_cb
    walk(self._in, args, self, name, 'request'))
  File "/usr/local/lib/python2.7/site-packages/neovim/plugin/host.py", line 65, in _on_request
    rv = handler(*args)
  File "/usr/local/Cellar/neovim/HEAD/share/nvim/runtime/autoload/provider/script_host.py", line 147, in python_eval
    return eval(expr, self.module.__dict__)
  File "<string>", line 1, in <module>
TypeError: unhashable type: 'list'

Nvim version:

NVIM 0.0.0-alpha+201510011537 (compiled Oct  1 2015 23:35:29)
Commit: 536c0ba27e79929eb30850d8e11f2ed026930ab3
Build type: RelWithDebInfo
Compilation: /usr/local/Library/ENV/4.3/clang -Wconversion -O2 -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -Wvla -std=gnu99 -fstack-protector-strong -fdiagnostics-color=auto -DINC
LUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovim20151001-45440-1mb22t4/build/config -I/tmp/neovim20151001-45440-1mb22t4/src -I/tmp/neovim20151001-45440-1mb22t4/deps-build/usr/include -I/tmp/neovi
m20151001-45440-1mb22t4/deps-build/usr/include -I/tmp/neovim20151001-45440-1mb22t4/deps-build/usr/include/luajit-2.0 -I/tmp/neovim20151001-45440-1mb22t4/deps-build/usr/include -I/tmp/neovim20151001-45440-
1mb22t4/deps-build/usr/include -I/tmp/neovim20151001-45440-1mb22t4/deps-build/usr/include -I/tmp/neovim20151001-45440-1mb22t4/deps-build/usr/include -I/usr/local/opt/gettext/include -I/usr/include -I/tmp/
neovim20151001-45440-1mb22t4/build/src/nvim/auto -I/tmp/neovim20151001-45440-1mb22t4/build/include
Compiled by [email protected]

Optional features included (+) or not (-): +acl   +iconv    +jemalloc
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/nvimrc"
     user vimrc file: "~/.nvimrc"
 2nd user vimrc file: "~/.nvim/nvimrc"
      user exrc file: "~/.exrc"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD/share/nvim"

Config .nvimrc:

set nocompatible
set hidden
set expandtab
let mapleader = "\<space>"

" plugin manager (vim-plug)
if empty(glob('~/.nvim/autoload/plug.vim'))
    silent !mkdir -p ~/.nvim/autoload
    silent !curl -fLo ~/.nvim/autoload/plug.vim
                \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    autocmd VimEnter * PlugInstall
endif
call plug#begin('~/.nvim/bundle')

" custom plugins
Plug 'L9'
Plug 'pik4ez/vim-colors-solarized'
Plug 'vim-airline/vim-airline-themes'
Plug 'tpope/vim-unimpaired'
"Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'edsono/vim-matchit', { 'for': 'html' }
Plug 'scrooloose/nerdcommenter'
Plug 'mattn/emmet-vim'
Plug 'Shougo/unite.vim'
Plug 'Shougo/vimproc', { 'do': 'make' }
Plug 'yuku-t/unite-git'
Plug 'sickill/vim-pasta'
Plug 'bling/vim-airline'
Plug 'Valloric/YouCompleteMe'
Plug 'SirVer/ultisnips'
Plug 'kana/vim-smartinput'
Plug 'kovetskiy/ash.vim'
Plug 'seletskiy/vim-pythonx'
Plug 'maksimr/vim-jsbeautify'
Plug 'kovetskiy/next-indentation'
Plug 'benekastah/neomake'

" Rust plugins
Plug 'rust-lang/rust.vim'

" 1. cd racer; cargo build --release
" 2. Set the RUST_SRC_PATH env variable to point to the 'src' dir in
"    your rust source installation
"    (e.g. % export RUST_SRC_PATH=/usr/local/src/rust/src )
" 3. Test on the command line:
"    ./target/release/racer complete std::io::B (should show some completions)
Plug 'phildawes/racer'

" Go support.
Plug 'fatih/vim-go'

" vim-go settings
let g:go_fmt_command = "goimports"

" xkb-switch required
" see https://github.com/ierton/xkb-switch
" after installation, set chmod +x /usr/local/lib/libxkbswitch.so
Plug 'lyokha/vim-xkbswitch'

Plug 'seletskiy/vim-autosurround'
inoremap  ( (<C-O>:call AutoSurround(")")<CR>

call plug#end()

" gui font for mac
set guifont=Monaco\ for\ Powerline:h12

set tags=./tags;,tags;

" racer settings (rust completion)
let g:racer_cmd = $HOME."/.nvim/bundle/racer/target/release/racer"
let $RUST_SRC_PATH=$HOME."/rust/rustlang-src/src/"

" unite settings
let g:unite_source_history_yank_enable = 1
let g:unite_source_history_yank_file = $HOME.'/.nvim/yankring.txt'
let g:unite_source_grep_command = 'pt'
let g:unite_source_grep_default_opts = '--nocolor --nogroup'
let g:unite_source_grep_recursive_opt = ''
let g:unite_source_grep_encoding = 'utf-8'
let g:unite_source_grep_max_candidates = 200

call unite#custom#source(
\ 'file,file/new,buffer,file_rec,file_rec/async,git_cached,git_untracked',
\ 'matchers', 'matcher_fuzzy'
\ )
call unite#custom#source(
\ 'file,file/new,buffer,file_rec,file_rec/async,git_cached,git_untracked',
\ 'ignore_pattern', '\<nodejs\>\|\<node_modules\>'
\ )
call unite#custom#profile('default', 'context', {
\   'start_insert': 1,
\   'direction': 'botright',
\ })
call unite#filters#sorter_default#use(['sorter_selecta'])
nmap <Leader>j :Unite -hide-source-names git_cached git_untracked buffer<CR>
nmap <Leader>b :Unite buffer<CR>
nmap <Leader>a :Unite ash_inbox<CR>
nmap <Leader>r :UniteResume<CR>
function! s:unite_my_settings()
    call unite#custom#alias('ash_review', 'split', 'ls')
    imap <silent><buffer><expr> <C-P> unite#do_action('split')
    imap <buffer> <C-J> <Plug>(unite_select_next_line)
    imap <buffer> <C-K> <Plug>(unite_select_previous_line)
endfunction

" surround settings
"let g:surround_45 = "\1function: \1(\r)"

" next-indentation settings
nnoremap { :IndentationGoUp<CR>
nnoremap } :IndentationGoDown<CR>

" ultisnips settings
let g:UltiSnipsSnippetsDir = "~/.nvim/ultisnips"
let g:UltiSnipsSnippetDirectories = ["ultisnips"]
let g:UltiSnipsEditSplit = 'horizontal'
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"

" youcompleteme settings
let g:ycm_key_list_select_completion = ['<c-n>']
let g:ycm_key_list_previous_completion = ['<c-p>']
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_seed_identifiers_with_syntax = 1

" disable scratch preview
set completeopt-=preview

" airline settings
set laststatus=2
let g:airline_theme='solarized'
let g:airline_solarized_reduced = 0
let g:airline_powerline_fonts=1
let g:airline#extensions#whitespace#symbol = '‚òº'
let g:airline#extensions#syntastic#enabled = 1
function! AirlineFixLength(...)
    let w:airline_section_z = airline#section#create(['%3p%%', 'linenr', '%3v'])
endfunction
call airline#remove_statusline_func('AirlineFixLength')
call airline#add_statusline_func('AirlineFixLength')

" syntastic settings
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_python_checkers = ['flake8']

" xkb-switch settings
let g:XkbSwitchEnabled = 1
let g:XkbSwitchIMappings = ['ru']

" ash settings
" don't ignore whitespaces
let g:ash_review_file_flags=''

set showtabline=0
set tabstop=4
set sw=4

set background=light
set t_Co=256
colorscheme solarized

" Directories for backup and swap files
set backupdir=~/tmp/vim,~/tmp,/var/tmp,/tmp
set directory=~/tmp/vim,~/tmp,/var/tmp,/tmp

" line numbers
set rnu

" wild menu
set wildmenu

" hidden symbols
set list
set listchars=eol:¶,extends:»,tab:│·,trail:·"
let g:solarized_visibility="low"
let g:solarized_contrast="normal"
let g:solarized_termcolors=256
let g:solarized_italic=0

" disable visual bells
set vb

" press F2 to paste without indent magick
set pastetoggle=<F2>

" mappings
nmap <Leader>w :w<CR>
nmap <Leader>d :bd<CR>
nmap gt :bn<CR>
nmap gT :bp<CR>
inoremap <C-j> <Esc>
inoremap <C-t> <C-o>:call search("[)}\"'`\\]]", 'c')<CR><Right>
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> :left<CR>
nnoremap <silent> <Space><Space> :nohlsearch<CR>
cnoremap w!! w !sudo tee % >/dev/null
nnoremap <Leader>c :e $MYVIMRC<CR>
noremap <F8> :bufdo bdelete<CR>
nmap <Leader>u :UltiSnipsEdit<CR>
vmap <Leader>` y:UltiSnipsEdit<CR>Go<CR>snippet HERE<CR>endsnippet<ESC>k]p?HERE<CR>zzciw

" cd to work dirs
command! Wa cd ~/work/avito
command! Was cd ~/work/avito-segm
command! Wav cd ~/work/avito-vagrant
command! Wspa cd ~/work/service-product-ads
command! Wspac cd ~/work/service-product-ads-client
command! Wscm cd ~/work/service-category-mapper
command! Wscmc cd ~/work/service-category-mapper-client
command! Wau cd ~/work/avito-utils
command! Waus cd ~/work/avito-utils-sphinx
command! Wspi cd ~/work/service-phone-info

" Copy current file path to * buffer
nmap <F4> :let @* = expand("%")<CR>

" Ctrl-U converts previous word to upper case
inoremap <C-u> <ESC>viwgUea

" F9 opens encoding menu
set wcm=<Tab>
menu Encoding.windows-1251 :e ++enc=cp1251 ++ff=dos<CR>
menu Encoding.utf-8 :e ++enc=utf8<CR>
map <F9> :emenu Encoding.<TAB>

" Ctrl-N breaks line in place of cursor
" Ctrl-M breaks line in place of cursor and jumps to the next space
" TODO remove space character under cursor before line breaking
" TODO create smart mapping to break arguments list inside function definition
nnoremap <C-n> i<CR><Esc>k$
nnoremap <C-m> i<CR><Esc>f<space>

" switch to previously selected buffer
nnoremap gl :b#<CR>

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

set history=50 " keep 50 lines of command line history
set ruler      " show the cursor position all the time
set showcmd    " display incomplete commands
set incsearch  " do incremental searching

" Don't use Ex mode, use Q for formatting
noremap Q gq

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
    set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
    syntax on
    set hlsearch
endif

set autoindent

" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
"filetype plugin indent on
filetype indent on
filetype on
filetype plugin on

augroup vimrcEx
    au!

    " For all text files set 'textwidth' to 120 characters.
    autocmd FileType text setlocal textwidth=120

    " When editing a file, always jump to the last known cursor position.
    " Don't do it when the position is invalid or when inside an event handler
    " (happens when dropping a file on gvim).
    " Also don't do it when the mark is in the first line, that is the default
    " position when opening a file.
    autocmd BufReadPost *
                \ if line("'\"") > 1 && line("'\"") <= line("$") |
                \ exe "normal! g`\"" |
                \ endif
augroup END

augroup confluence
        au!
        au BufRead /tmp/vimperator-confluence* set ft=html.confluence | :call HtmlBeautify()<CR>
        au BufRead /tmp/vimperator-confluence* map <buffer> <Leader>t :%s/\v[\ \t\n]+\<p\>([\ \t\n]+\<br\>)?[\ \t\n]+\<\/p\>/<CR>
augroup end

augroup erlang
    au!
    autocmd FileType erlang setlocal ts=4 sts=4 sw=4 noet
augroup END

augroup php
    au!
    autocmd FileType php setlocal colorcolumn=80,120
augroup END

augroup html
    au!
    autocmd FileType html setlocal et
augroup END

augroup go
    au!
    autocmd FileType go setlocal noet
    autocmd FileType go setlocal colorcolumn=80,120
augroup END

augroup python
    au!
    autocmd FileType python setlocal colorcolumn=79,120
augroup END

augroup sh
    au!
    autocmd FileType sh setlocal colorcolumn=80
augroup END

augroup c
    au!
    autocmd FileType c setlocal colorcolumn=80
augroup END

augroup unite_setting
    au!
    au FileType unite call s:unite_my_settings()
augroup end

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
    command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis
endif

" Auto reload vimrc on change
augroup vimrc
    au!
    au BufWritePost ~/.nvimrc source % | AirlineRefresh
augroup end

" Neomake settings
autocmd! BufWritePost * Neomake

" Make pizdato
nnoremap <Leader>m :call TryToReduce()<CR>
function! TryToReduce()
    let startLine = line(".")
    let content = getline(startLine)
    let content = substitute(content, "[,\(]", "&\r", "g")
    let content = substitute(content, "[\)]", "\r&", "g")
    let content = substitute(content, "\(\r\r\)", "()", "g")
    let content = substitute(content, "\rarray\r", "array", "g")
    execute 'normal S'
    execute 'normal i' . content
    let currentLine = line(".")
    let cow = currentLine - startLine + 2
    execute 'normal ' . (startLine - 1) . 'gg'
    execute 'normal ' . cow . '=='
    execute 'normal ' . startLine . 'gg^'
endfunction

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.