emacs-evil / evil-surround Goto Github PK
View Code? Open in Web Editor NEWyou will be surrounded (surround.vim for evil, the extensible vi layer)
License: Other
you will be surrounded (surround.vim for evil, the extensible vi layer)
License: Other
The pipe indicates the cursor position:
This is a test |sentence.
yssfprint
|print(This is a test sentence.)
C-_
|This is a test sentence.
The expexted result is:
This is a test |sentence.
The same happens when I add a tag instead of a function call. However, adding quotes and undoing puts the cursor in the original position.
I would absolutely love to be able to do something like V-S-RET
, that is, select some lines, press the surround operator and then give it an argument of RET so that it surrounds the lines with empty lines. I find myself doing this sometimes to space logically-grouped chunks of code. Doing this via the surround bindings feels the most natural way to do this, so I'm wondering if there's a way.
I tried doing it out of the box but it instead added little ^M
markers, which I guess is essentially two lines, or something.
Before:
(use-package evil-surround
:config ;; point is here
(global-evil-surround-mode 1))
After:
(use-package evil-surround
^M
:config
^M
(global-evil-surround-mode 1))
Expected:
(use-package evil-surround
:config
(global-evil-surround-mode 1))
So next I tried to add my own surround pair (btw ^M
is the effect of C-v RET
):
(push '(?^M . ("\n" . "\n")) evil-surround-pairs-alist)
But then I end up getting two lines instead of one, and the second one that appears on the bottom is indented, and the previously-following non-whitespace line is unindented.
Before:
(use-package evil-surround
:config ;; point is here
(push '(?^M . ("\n" . "\n")) evil-surround-pairs-alist)
(global-evil-surround-mode 1))
After V-S-RET
:
(use-package evil-surround
:config
;; intended to here; the other empty lines are properly unindented. notice next is incorrectly unindented
(push '(?^M . ("\n" . "\n")) evil-surround-pairs-alist)
(global-evil-surround-mode 1))
Perhaps this is outside of the scope of evil-surround. I would love it if I could use these bindings though. If this isn't possible via evil-surround, could I perhaps hook on my own function that does this to some evil-surround map so that I can trigger it when I press S
and RET
?
Expected: Return to visual mode without any surrounding characters
Got: ^[
surrounding the visual region
Copied from syl20bnr/spacemacs/issues/814.
Hi,
since the last update, typing "s" from inside visual-state just kills the region and switches to insert-state.
That is the normal evil-mode behaviour without evil-surround.
Thanks
This is a test |sentence.
The pipe is the cursor. Doing ds"
results in the following error:
byte-code: Wrong type argument: integer-or-marker-p, nil [2 times]
Doing dst
when there is no surrounding tag does not produce an error.
Thanks for the nice package! It is quite useful editing a language where you can exchange single and double quote such as Python.
It would be much better if this bug is fixed: Let's say you have
aaa "bbb"
and used cs"'
in the quotes, then you will have:
aaa'bbb'
Error (use-package): evil-surround :init: Symbol's function definition is void: global-evil-surround-mode
i.e., it changes:
(this-form)
to:
[ this-form ]
Desired functionality: preserve original spacing (or lack thereof).
I couldn't think of a more discriptive name, sorry.
If I modify surround-pairs-alist
as such:
(setq surround-pairs-alist (append '((?` . ?')
(?' . ?'))
surround-pairs-alist))
s' and swill do the same: Surround the selection with
'
If I switch the lines alls fine: s' surrounds with ' ' and swith
'.
This package is absolutely brilliant, and makes me feel like a code editing ninja. However, it doesn't seem to add the action to Evil's list of past commands - for example, I might have a list of numbers that need to be enclosed in parenthesis, and try to do ysiw" on one of them, and do the rest with move and . (inspired by Practical Vim). In this case, . repeats the action I did before ysiw", not ysiw". I've tried different surround commands, and this is always the case.
Is it possible to allow for more than just (
when using Sf
on a visual selection? I have tried entering text[
in the minibuffer but that didn't seem to work.
Hey there,
Evil-surround overwrites evil-substitue. In vim visual mode, vim-surround only uses capital S, and not s, since s is used for substitute.
Hi there,
In the README.md where you give an example of adding a new pair:
(setq-default evil-surround-pairs-alist (cons '(?~ ("``" . "``"))
evil-surround-pairs-alist))
Instead it should be :
(setq-default evil-surround-pairs-alist (cons '(?~ . ("``" . "``"))
evil-surround-pairs-alist))
I thought I'd point it out and save another Elisp newbie from my pain trying to figure out why it wasn't working. Sorry for cluttering the issues otherwise!
Hi Tim!
I'm working with a company that only allows licensed software to be downloaded. I didn't see any in the code - is this released under some open source license?
Thanks in advance!
Bobby
I have the following keybindings in init.el
(define-key key-translation-map (kbd "[") (kbd "("))
(define-key key-translation-map (kbd "]") (kbd "["))
(define-key key-translation-map (kbd "(") (kbd "{"))
However evil/surround will ignore them and use the regular keys, i i would like to wrap a world with () it becomes [] with evil/surround.
Is there a possible fix for this?
Also after watching this https://www.youtube.com/watch?v=5HF4jSyPpvs not much of what he shows work with this plugin, am i doing it wrong for example the dst cat does not work?
(push '(?0 . ("{-" . "-}")) evil-surround-pairs-alist)
I can insert {- -}
with s0
but ds0
does nothing.
Emacs 24.5.1
evil-surround 20150605.2306
the relevant config
(setq-default evil-surround-pairs-alist (cons '(?= . ("=" . "="))
evil-surround-pairs-alist))
(global-evil-surround-mode 1)
I would now assume given
=as(!)df=
where (!) is caret, that a cs='
would change the =
delimiters to '
quotes. However, after pressing =
nothing happens (caret turns back from visual indication of waiting for further input to "normal" caret). How can I debug this?
I want to change this block of text
http://www.plosone.org/article/feed/search?unformattedQu
http://www.plosone.org/article/feed/search?unformattedQuery=subject%
http://www.plosone.org/article/feed/search?unformattedQuery=subject%3A%2
into this
"http://www.plosone.org/article/feed/search?unformattedQu"
"http://www.plosone.org/article/feed/search?unformattedQuery=subject%"
"http://www.plosone.org/article/feed/search?unformattedQuery=subject%3A%2"
According to the instruction you can surround in visual-state with s<textobject><trigger>
. But what you get is :
"http://www.plosone.org/article/feed/search?unformattedQu
http://www.plosone.org/article/feed/search?unformattedQuery=subject%
http://www.plosone.org/article/feed/search?unformattedQuery=subject%3A%2"
If I surround a word, ysiwb
for example and then try to use the .
operator to surround another word, I get: After 0 kbd macro iterations: evil-motion-range: Args out of range: "", 0
Is this a bug or is the dot operator unsupported?
thanks in advance.
This package seems incredibly useful. Please consider adding it to MELPA. That makes it easier for users to install it and to keep it up-to-date. Thank you.
evil-surround-region behaviour has changed for visual line mode
Observed behaviour:
{qwe
asd
zxc}
Expected behaviour:
{
qwe
asd
zxc
}
For visual and visual block mode, the observed behaviour is expected and correct, for visual line mode it is wrong imho. This has changed recently, before it did work as expected.
Hello,
With the following text (haml-mode):
%h2 Sign in
= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:class => "form-vertical" }) do |f|
= f.input :email, :autofocus => true
= f.input :password
= f.input :remember_me, :as => :boolean if devise_mapping.rememberable?
= f.button :submit, I18n.t("common.sign_in"), :class => 'btn-primary'
= render "devise/shared/links"
If I put my cursor somewhere inside the btn-primary
text, and press cs'"
then it works but the next line is joined to the current line.
If you run have a string like the following
.where(['some query'], %w(additional stuff here)])
And with your curser on the "a" in additional and run the command "di(" it will generate the string:
.where()
rather than:
.where(['some query'], %w()])
This seems to happen on all nested commands.
Given
aaa 'bb|b' ccc
ysa') yields:
aaa ('bbb' )ccc
Even if you add (setq which-key-allow-evil-operators t),
Evil-Surround is not showing which-key popup.
For brief example, on Vs there is no popup,
as there is none on any other selection I've tried.
Most probably due to its implementation,
it being different than other operators.
I'll give all info you need if anyone fails to repro it.
Hello,
I think evil-surround doesn't work as expected with vertical selections. If you vertically select a few lines and press s, in vim whatever was selected will be deleted (surround will have no effect whatsoever); with evil-surround, it will surround whatever you had selected with the letter you pressed after s. I'm not sure that is expected behavior.
My package-archives includes elpa, melpa and marmalade.
It took me a while to figure out what the difference was between "surround" and "evil-surround"; the latter is a renamed version of the former. Surround should probably be removed from the repository to stop people downloading the old version (and stop confusion in general); I was using surround for a while myself.
"Brain | and Language"
When I cs"{
, I get this result:
|{ Brain and Language }
Not sure if bug, but I would prefer, if there were no additional spaces in the result.
In the documentation it is suggested to fix the conflict with evil-paredit with the following snippet:
(add-to-list 'surround-operator-alist
'(evil-paredit-change . change))
(add-to-list 'surround-operator-alist
'(evil-paredit-delete . delete))
However, surround-operator-alist does not appear to be an actual variable. Is this supposed to be evil-surround-operator-alist?
The documentation for evil-surround-edit
is inaccurate when compared to the code for the function itself.
The documentation string:
"Edit the surrounding delimiters represented by CHAR.
If OPERATION is `change', call `evil-surround-change'.
if OPERATION is `surround', call `evil-surround-region'.
Otherwise call `evil-surround-delete'."
The actual conditional branch is a cond that checks if the operation is 'change
, then checks if it's 'delete
, and then ultimately calls evil-surround-region
.
The proper documentation string should be:
"Edit the surrounding delimiters represented by CHAR.
If OPERATION is `change', call `evil-surround-change'.
if OPERATION is `delete', call `evil-surround-delete'.
Otherwise call `evil-surround-region'."
"Brain | and Language"
When I cs"{
, I get this result:
|{ Brain and Language }
Typically, it would be more useful for me if the cursor was in the same position after this operation. Are there any conventions in Vim that apply to this issue?
Given a text
some text
yss)
should surround the entire line without adding new lines.
(some text)
but evil-surround adds the () on new lines
(
some text
)
Since it's possible to wrap a text object in a function call with, e.g., yssf
, I would expect dsf
to delete that function call. Seems like a very useful feature.
I add (push '(?~ . ("~" . "~")) surround-pairs-alis
as a hook for org-mode and now the surround-pairs-alist is:
((61 "=" . "=")
(126 "~" . "~")
(40 "( " . " )")
(91 "[ " . " ]")
(123 "{ " . " }")
(41 "(" . ")")
(93 "[" . "]")
(125 "{" . "}")
(35 "#{" . "}")
(98 "(" . ")")
(66 "{" . "}")
(62 "<" . ">")
(116 . surround-read-tag)
(60 . surround-read-tag)
But I cannot use cs~*
for ~test~
; it also fails with =test=
.
BTW, evil-surround works smoothly for default pairs like cs"'
for "test"
in org-mode.
It would be nice to insert and delete newlines with evil-surround.
For example ds<RET>
inside:
line
paragraph
paragraph
line
would result in
line
paragraph
paragraph
line
When surrounding some text range with a tag text object where the tag has an attribute, e.g. <a href="http://foo.bar">
, I am always forced to include the closing " in my input. Simply entering <a href="http://foo.bar
wouldn't properly close the tag. On the other hand, it is apparently acceptable to omit the closing >.
Supporting omitted closing quotes wouldn't be too hard to implement, I think.
On the other hand I must admit that vim doesn't support this either, so this will probably end up as wontfix. But I believe this is a bug in vim rather than a feature. Would you recommend to first file a feature request with vim?
With the following:
first second third not
placing the cursor at the beginning of the line and entering
ys3w{
I get
{ first second third }not
When I do the same thing in Vim I get
{ first second third } not
which is what I expected.
The text is "char(len)" and I want to change it to char[len], "csb[" doesn't
work in this situation.
In this text file, with your cursor in the middle of the word 'this':
5'11" tall
change "this" word
attempting to manipulate the surrounding quotes (ds"
, cs"
, etc) returns a "No quoted string found" error. In Vim with surround installed, the quotes are correctly detected and manipulated.
I believe this is due to Evil's quote textobject using native Emacs quote parsing, per this thread. Also per that thread, it sounds like Evil itself is not going to change the way quote textobjects are parsed, so a change to make surround behave normally would have to be made in evil-surround itself.
I'm currently working on some patches, one would add a documentation.
I draw on the examples from surround.vim and there isyssb
on this line:
{ Hello } world!
The expected would be
({ Hello } world!)
but it is (make emacs on the latest evil)
(
{ Hello } world!
)
I'm not sure if the problem lies with evil's sentence (line?) text object or evil-surround but since I can only think of surround to reproduce this I'll submit it here.
Hello,
evil surround seems to fail for me on strings in some Ruby files. Specifically, I have noticed the problem in RSpec style test files. The problem is not consistant however and I have been unable to find any kind of pattern to the failures. While the failures are not consistent between different files, they are consistant on the same file. For example, on my machine, the following code snippet will consistently cause evil surround to fail with the error:
Wrong type argument: integer-or-marker-p, nil
when I attempt to replace any of the quotation marks. Other delimiters such as parens and curly braces still work as expected.
describe "#some_method" do
before do
@target.stub!("foo") {|_|}
end
it "sets the foo to the passed in value" do
@target.shouldUpdateCellWithObject("bar baz")
@target.viewModel.should == "bar baz"
end
it "calls foo with the bar baz" do
@target.mock!("foo") {|vm| vm.should == "bar baz"}
@target.shouldUpdateCellWithObject("bar baz")
end
it "returns true" do
@target.shouldUpdateCellWithObject("bizzle").should == true
end
end
The problem seems to extend even deeper however. If I open a ruby buffer and just put a string into it, e.g.
"yodel"
Surround will fail with the above error when I try to replace the quotes. However if I wrap that string in a function definition, e.g.
def fizzle
return "yodel"
end
Then replacing the quotes works as expected.
Is there anything to explain this behavior?
I learned from here http://kana.github.io/config/vim/surround.html that yss should operates on the current line, ignoring leading whitespace. But it always includes the leading whitespace on my machine, which looks bad. I am using emacs 24.3.
Any ideas?
Thank you!
Hi all
I use Dvorak keyboard, and have s key already binded. how to change "s" to "k" in visual mode.
I've tried
(evil-define-key 'operator surround-mode-map "k" 'surround-edit)
(evil-define-key 'visual surround-mode-map "k" 'surround-region)
(evil-define-key 'visual surround-mode-map "K" 'Surround-region)
and
(define-key evil-visual-state-map "k" 'surround-region)
with no success.
Can anyone please help.
Thanks
Hi guys,
In vim I'm used to adding delimiters (e.g. parens) in insert mode with CTRL-s ), and I combine this with 'let g:surround_insert_tail = "<++>"' and imaps.vim to then jump to the marking with CTRL-j. Is such a thing possible with evil-surround? I don't really mind removing the search functionality from CTRL-s.
with (provide 'evil-surround)
at the end instead? seems more logical and better for package managers and package users.
Thanks for making this useful package available.
Is there a way to surround multiple words.
For example to go from foo b|ar baz baa
to foo *bar baz* baa
.
I tried ys2aw*
but this gives foo *bar baz* baa
.
Similar behavior with ys2aw(
or ys2aw)
.
I am using surround from melpa with emacs 24.3.
Repeating surround changes with dot e.g. works for:
cs"(
ds(
It however does not work for many other cases (e.g.):
ysiw<pre>
cst<stong>
I checked that vim-surround also has some limitations, but
hopefully you dont try to be 100% compatible ;-)
All executed from normal mode
When trying to surround some selected text with s(
, extra spaces are added too, for example I get ( evil )
when what I want is just (evil)
. I'm having this problem with (
's and [
's but the problem doesn't exist for quotation marks.
For example, in html-mode,
<t>a-1-aa</t>
"b-2-bb"
<t>ccc</t>
issuing cst"
at cursor position 1 results in
'a-1-aa'
"b-2-bb"
<t>ccc</t>
while cs"'
at cursor position 2 results in
<t>a-1-aa</t>
'b-2-bb'<t>ccc</t>
It appears more consistent to make the second case to behave like the first one.
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.