tpope / vim-surround Goto Github PK
View Code? Open in Web Editor NEWsurround.vim: Delete/change/add parentheses/quotes/XML-tags/much more with ease
Home Page: https://www.vim.org/scripts/script.php?script_id=1697
surround.vim: Delete/change/add parentheses/quotes/XML-tags/much more with ease
Home Page: https://www.vim.org/scripts/script.php?script_id=1697
Suppose I have the following code (ft=c):
//calculate sum
for (size_t idx = 0; idx < size; ++idx)
{
sum += array[idx];
}
//use sum for calculations
do_something(sum);
I want to remove the block braces, so I put the cursor inside them and say "dsB". This works fine for the braces, but incorrectly moves the comment up above the loop body, like this:
//calculate sum
for (size_t idx = 0; idx < size; ++idx)
//use sum for calculations
sum += array[idx];
do_something(sum);
The same behavior occurs if the loop body spans multiple lines.
I'm in the popup_info string in this issue's Title, type cs'" and instead of replacing the single quotes with double quotes, a space + double quotes is added.
when i just recordet macros q0 some actions 'q'
then im trying to sorround some selected text wish 's
' and since my macro is broken.
how to solve ?
I want to get
<p>donkey</p>
to
<p>
donkey
</p>
by going to d, veS<enter>
. The current result:
<p>^Mdonkey^M</p>
(perhaps I've got something badly confed.) Cheers
is there a way to disable automatically matching a single quote? can't find a solution anywhere so far.
thanks again for this great plugin.
Try the following line in your erb file:
<a href="<%= profile_path %>"><%= current_user.name %></a>
Put cursor on current_user and press dst.
My result:
"><%= current_user.name %>
Expected result:
<%= current_user.name %>
If i start with:
aaa ( |bbb ) ccc
where | is my cursor and type ds) I get
aaa ccc |bbb
The interesting part being that the bbb line has now jumped above the ccc line. I would have expected bbb to stay above ccc in the file.
Hi,
I'd like to use your plugin for editing Trac wiki pages. In this language sections have more than one = level, for instance:
= Section1 =
== Section2 ==
=== Section3 ===
would it be possible to specify a number before the character to wrap? For instance if I want to convert a text into Section3 header it will be something like cs<text_selection>3=
Thank you
I am getting started with surround.vim and I installed the corresponding repeat.vim, but when I do "." to invoke the repeat operation, it does not "repeat" the prior surround.vim operation. I am sure that I installed repeat.vim correctly. I notice that repeat.vim was last changed in 2008. Is there a newer version that I should be using?
I am using vim 7.2 on a Windows XP machine.
Thanks in advance
Not sure if this is a feature request or a bug, but it would be very nice to be able to repeat operations like:
viws)
I have the most up-to-date surround and repeat from git installed. Operations like:
cs)]
do repeat properly for me, so I believe I have installed the files correctly.
Thanks and I love your plugins!
An idea to have the 'sif' command that surrounds selected text with if conditional statement like
Ruby example.
Before:
article.publish!
After:
if
article.publish!
end
The problem is that it depends on the current buffer file type e.g. Ruby, ERB, JavaScrit etc.
Is that possible to implement with surround.vim?
If I need to put something into a LaTeX environment
it's usually a longer piece -- one or more paragraphs --,
and it's anyway most convenient to just open a line,
type in the \begin{} line, move down, open another
line and type in the \end{} line.
For me a far more common use case is that I'm marking
up an existing text and want to surround a smaller text
object -- a word/WORD/sentence -- with a command,
making the text object the argument of the command.
To handle the cases beyond the most common commands
I've put the following in my .vimrc:
autocmd FileType tex let b:surround_{char2nr("\\")} = "\\\1\\\1{\r}"
I would like to have a switch to change between the
environment and command argument behavior of the \
target and back. Even if that can't be I hope you put
the above customization as an example in the
documentation, since I believe very many who regularly
mark up text written by others for LaTeX would find it
very useful.
A cosmetic and hence not very important wish would be for the
prompt to appear just as \
similar to <
with an XML tag.
As of now, surrounding (by addition or change of surroundings) with «, », ‹ or › inserts the same character twice (resulting in things like «sometext«).
« and » are opening and closing double angle (AKA "French") quotation marks: https://en.wikipedia.org/wiki/%C2%AB
‹ and › are opening and closing simple angle quotation marks (same article)
This was me being stupid; there doesn't seem to be a way for me to delete the issue entirely.
maybe I missed it and I'm also a vim noob but is there a way to easily change whats inside of a surrounding tag? e.g. if I yank a string "hello"
and want to change just hello
with something else; is there a way for surround to figure out what surrounds the word and delete everything around it besides the "surrounding" tag,quote,whatever, so I can replace whats inside. Hope that makes sense. Love this plugin.
Would it be possible to combine what VS does with indentation-recognition (as in http://www.ibm.com/developerworks/linux/library/l-vim-script-2/index.html#A%20function%20to%20help%20you%20code )?
As it is, VS has 1 line as its default scope. It would be nice if some command like ViS would take indentation into account.
<example1 />
<example2>
<example3 />
<example4 />
</example2>
<example5>
<example6 />
</example5>
↓ with the cursor on <example3 /> or <example4 />: ↓
<example1 />
<example2>
<surround>
<example3 />
<example4 />
</surround>
</example2>
<example5>
<example6 />
</example5>
Or even better would be to also encompass all further indentation:
<example1 />
<example2>
<example3>
<example4 />
</example3>
</example2>
<example5>
<example6 />
</example5>
↓ with cursor on <example 3> or </example3>: ↓
<example1 />
<example2>
<surround>
<example3>
<example4 />
</example3>
</surround>
</example2>
<example5>
<example6 />
</example5>
After using a cs"> command, repeat (.) only changes the closing character. It should repeat the entire sequence.
It would be convenient for C and C++ programmers to have #ifdef VALUE\r...\r#endif
preprocessor directive support. It is very commonly used for both commenting code #ifdef 0
and checking for platform features to make the code portable.
I try add this to my vimrc
let g:commentChar = {
\ 'vim': '"',
\ 'c': '//',
...
\ 'cpp': '//',
\ 'sh': '#',
\ 'python': '#'
\}
let comChar = g:commentChar[&ft]
let g:surround_{char2nr('z')}=comChar."{{{ \r ".comChar."}}}"
let g:surround_{char2nr('Z')}="\" \<++\> {{{ \r \"}}}"
but I get this error message
Error detected while processing ~/.vimrc:
line 290:
E713: Cannot use empty key for Dictionary
E15: Invalid expression: g:commentChar[&ft]
line 291:
E121: Undefined variable: comChar
E15: Invalid expression: comChar."{{{ \r ".comChar."}}}"
I just download this vim script and find it great!
But, while I can use 'ysiw;' to surround text with semicolon,
I can't use 'ds;' to delete it, and so does 'cs;'
Is that this script intentionally does this?
//sorry for my poor English
If I enter
;Ti*le;
(star* being current cursor position) and then try to change via say typing
cs;'
nothing happens.
Deletion also does not work - typing
ds;
does nothing.
Deletion also does not work for $ character:
when standing on
source $$VIM*RUNTIME$/vimrc_example.vim
and typing
ds$
Recently, whenever I select something and try to use surround in visual mode (either s" or gs"), the s key causes the selected text to be deleted. I am using the latest revision from the master branch (c912039) and have verified there is no conflict with vimrc or other plugins. The latest version from vim.org (1.90) works as expected.
Just like issue #2 presents, after doing a surround command, the cursor always goes to the beginning of the operand text.
It'd be more efficient if there's an option to keep the cursor where it was before . Is it possible?
Text: Hel^lo
^ - indicates cursor position
Input: viws'
Result: 'Hello '
OS: Windows XP
Vim 7.2
Not sure about it
Have a line
"Exclaim"
Type
yss(
Result
( "Exclaim" )
Type
yss)
or
yssb
Result
("Exclaim")
From documentation
Eight punctuation marks, (, ), {, }, [, ], <, and >, represent themselves
and their counterparts. If the opening mark is used, contained whitespace is
also trimmed. The targets b, B, r, and a are aliases for ), }, ], and >
(the first two mirror Vim; the second two are completely arbitrary and
subject to change).
trimmed caused a question for me when i finally figured out how to add braces without extra space
These lines may refer to change and delete use cases and not adding surrounding, but not very clear.
Hi,
it would be awesome if the $ sign (as used in LaTeX to show equations) could be a surrounding environment, like <>, (), etc.
Thanks for an awesome package.
Here are 2 examples for somewhat strange behavior
First line is what we had before
Second - surrounding used
Third - result
The main issue is that ',' gets into surrounding, which isn't very obvious.
IN VISUAL - selection is between | | reply to |"me"|, urgent S} reply to {"me",} urgent reply to |"me|", urgent S} reply to {"me|"}, urgent
Please add doc/tags to gitignore to enable this plugin to be used as a pathogen bundle through git submodules
The plugin is handy but this is a little awkward. I am trying to change the selected text by typing "s" in visual mode.
I made a video clip to show you and put it on here too. You can get it like:
curl 'http://gist.github.com/raw/554437/d74732514a01325f8250aecae8bebf431ebea099/example-of-surround.vim-problem.avi' | base64 -d >problem.avi
The MD5 sum should be f4d8f0c74ba736c2e0240b11924e37c5.
Hi,
I don't exactly understand what the above line does. It messes up my usual editing behaviour though. I usually visually select an element of text with 'v', then press 's' and type whatever I want the selected text to be replaced with. However, loading the vim-surround plugin results in the error message above.
I understand that I can simply do an 'unmap s' to restore the normal behaviour but I wonder why the remap is actually in place?
Thanks,
Jochen
I disagree. "You surround". Or for the common usage case of ysiw, "You see it wrapped!"
It doesn't delete matching character surrounds. Works fine on () {} [] etc.
start with:
*f|oo*
where | is the cursor and type ds* it does nothing. I'm using win32 gvim.
I'm only saying this because I can insert *,&,%,etc. surrounds with the tool so I would expect it to be able to get rid of them as well.
Thanks for the awesome plugin!
When I add a surrounding in visual mode the line is indented with a tab.
Is there a way to add a 2 space indentation instead?
i've just discovered vim-surround and this is a godsend for editing lisp code in vim.
however, i find that when adding parens the additional whitespace forces me to delete said space on the closing parens.
is there any way to change this? i am not so well learned in reading vim scripting code.
maybe a pointer in the docs on how to disable this manually would be just fine.
thank you for this very handy script.
when on an empty string literal: |""
cs"' doesn't work
when i press dsb it deletes a text inner ( ) . but i didn't find it in documentation.
It seems that cs
and ds
doesn't work inside a string like ## Configuration ##
. Considering that cursor is on 'g' character, issuing cs#"
or ds#
has no effect, despite it does work if #
is replaced by '
on the string and commands.
Thanks for sharing this awesome plugin!
There is already "ys..l" for surrounding something in a LaTeX environment, e.g. type (from normal mode)
ysiwl
center<CR>
for the effect
foobar -> \begin{center}foobar\end{center}
Similar to "l", I added to my local copy the letter "c" which wraps not in a LaTeX environment, but in a LaTeX command, e.g.
ysiwc
textbf<CR>
has the effect
foobar -> \textbf{foobar}
Here's what I added to s:wrap in my surround.vim, near the code that creates the environments. My code is based on the behavior of "f" as in "function".
elseif newchar ==# 'c' || newchar ==# 'C'
" LaTeX command
let cmd = input('command: ')
if cmd != ""
let before = substitute(cmd,'{$','','').'{'
let before = '\'.substitute(before,'^\','','')
let after = '}'
if newchar ==# 'C'
let before .= ' '
let after = ' ' . after
endif
endif
After reading the docs and closed issues here, I understand repeat.vim can't fully repeat yss
, so I'm wondering: Is there another super fast way to build a list?
Let's say I have plain text:
Item one
Item two
Item three
I can navigate to Item one
, hit yss<li>
to surround it, but can't repeat it properly on the next 2 items.
I was trying to find a way to use cs
instead since the docs say it can repeat, but how would you use cs
to do what I'm trying with yss<li>
? Perhaps there's a better way? Tried macros but couldn't get it to work right.
Commit f6c9d3b prevents me from selecting text and using s
to start replacing it. It displays an error.
Maybe something like this would be more appropriate:
xnoremap <silent> <Plug>Vsurround :<C-U>echoerr 'surround.vim: Visual mode s has been removed in favor of S'<CR>
The surround.vim plugin masks the 's' command in visual mode, replacing it not by an awesome feature (like many other key combos), but with a useless ;echoerr stating that I should use 'S' instead. I definitely did not want to press 'S' instead, since pressing 's' in visual mode is a standard Vim command (see ':help v_s'). I know it's the same as 'c' (see ':help v_c'), but it's hard to change many years of muscle memory training. :)
Anyway, I hope you agree masking normal Vim behaviour with just an error message (and not with added features) is not intended behaviour, so please remove the :echoerr. Thanks!
Hello,
I use the surround-change operation (not sure if that is the official name) to switch between single and double quotes for strings in my Ruby program.
While trying to make shortcuts for the aforementioned operation, I noticed that the cursor moves to the beginning of the operand text after the operation. I tried to solve this by restoring Vim's default "position before the latest jump" marker (see :help '') as suggested by a person named "elik" in the #vim IRC channel:
nmap <leader>' cs"' ``
nmap <leader>" cs'" ``
But this did not work. Instead, I had to use an explicit temporary (I hope) marker:
" switch between single and double quotes (surround plugin)
"
" NOTE: we explictly set a temporary marker (z) and restore it after
" the surround operation because the surround plugin does not
" restore the cursor position after the surround operation; it
" leaves the cursor at the opening quote of the operand instead!
"
nmap <leader>' mz cs"' `z
nmap <leader>" mz cs'" `z
Perhaps surround.vim is interfering with this default Vim marker?
Thanks for your consideration.
I would like if I do the following type of command:
cs'SOME_HTML_TAG
I should see the 'thing' I'm replacing with, so in this case - SOME_HTML_TAG
in the commandbar. Or somewhere
Is this do-able?
This has been bothering me for ages, but maybe I'm just doing something wrong.
I have vim-repeat installed and it dutifully repeats commands, but it doesn't repeat the entire command. Say I do ysiw"
to surround a single word with double quotes, and now I move the cursor to a different word and hit .
, I would just expect that word to be surrounded with double quotes. Instead, I need to strike "
again.
So usually this goes ysiw"j."j."j."j."j."j."j."
, etc... It would be so much faster if I could just do ysiw"j.j.j.j.j.j.j.
. And in my opinion that's more inline with how vim's other commands behave (e.g. ciw
).
Am I doing something wrong, or is this intentional? If so, why?
Using the latest vim-surround, installed via pathogen, I get a strange ~1second delay with my remapped cursor up key. Below is a pared-down version of my .vimrc, with my minimally useful set of remappings. During testing, the only thing in my .vim/bundle directory is vim-surround, cloned from this repo.
call pathogen#infect()
" enter command-line window
noremap qs q:
" command-line history
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
" up-arrow
noremap c k
" down-arrow
noremap t j
" right-arrow
noremap n l
" find-prev
noremap C N
" find-next
noremap T n
" 'til
noremap l t
" back 'til
noremap L T
" help
noremap J K
" join-lines
noremap j J
" change-to-eol
noremap K C
" change
noremap k c
" subst-line
noremap : S
" subst
noremap ; s
" ex cmd line
noremap S ;
" repeat t/T/f/F
noremap s :
Strangely, my regular cursor keys work fine, no delay. And if I use the normal 'k' cursor-up key, it also works fine. It's only when I use my mapping of 'c' to 'k' that I experience the delay.
Removing vim-surround rectifies the problem.
This seems so obvious that I apologize if it's been addressed elsewhere, but: it would be great, once I've deleted a complicated HTML tag surround using dst, to be able to then put it around some other text, with a command like perhaps yswp.
Is this way more difficult than I realize?
It would be handy to have a cS command that acts like yS by putting the resulting text on its own line.
For example:
results = Entry.objects.filter(title='foo', author='bob').count()
^
|
Cursor
Press cSbb
and get:
results = Entry.objects.filter(
title='foo', author='bob'
).count()
some languages have many accented chars like áàãçéêíôöú so it requires 2 keystrokes to insert single and double quotes which breaks the cs'"
and cs"'
commands.
to test it just change your keyboard layout to U.S. International and try to insert a quote - the quote is only placed if the following char can't have an accent or if you press space.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.