# Tag Info

## Hot answers tagged plugin-vim-surround

10

It's not specific to vim-surround - va' also selects the leading whitespace. From :h a': a" v_aquote aquote a' v_a' a' a v_a a "a quoted string". Selects the text from the ...

10

The plugin vim surround allows you to choose whether you want spaces and parenthesis or just parenthesis. You can disable it by using other mappings; actually you pasted them in your question, as the second and third examples. This is actually a pattern in the mappings of this plugin: if you use the opening character - e.g.: (, { and [ - them it will ...

6

If vim-surround were implemented as 's' and 'S' (pseudo-)text-objects instead of operators ds, dS, cs, cS etc, this wouldn't be an issue. I don't know if there's some technical reason for this design choice, but anyway one solution would be to write your own wrapper omap: let g:surround_no_mappings = 1 function! SurroundOp(char) if v:operator ==# 'd' ...

6

You can create a customize surround by defining a variable g:surround_{key code} So for example you could do let g:surround_96 = "\r'" Where 96 is the key code for . You can make this more readable by putting by letting vim determine the key code by using let g:surround_{char2nr("")} = "`\r'" \r will be replaced by the relevant text. If you only ...

5

As mentioned by grodzik, nnoremap does not take any non-standard mappings into account. That includes mappings by plugins. Simply changing to nmap is not the right way to go in my opinion. You will start to get used to Alt ( and not need ysiw) anymore. With an nmap you will never be able to map something else to ysiw) (or ys) because that will break the Alt (...

5

The surround plugin defines global mappings. Unfortunately, you can only override those with buffer-local ones, but not :unmap them only in the buffer. Temporarily disabling and re-defining the global surround mappings would be possible, but is cumbersome. I think the best solution would be patching the netrw plugin to add the <nowait> argument to the ...

4

I found a workable solution by changing the following vim core settings. :filetype indent on :set smartindent In my case I was editing an HTML file - which vim had no trouble detecting as the correct filetype, but if you were editing any other HTML-containing file that vim didn't recognise correctly, you may need to add: :set filetype=html Those ...

4

Yes, s is a synonym for cl. tpope/vim-surround does not change this, it adds new operators. The full list of operators that vim-surround adds is ds<foo> which the mnemonic is (D)elete (S)urrounding foo. For example, ds", or ds( cs<foo><bar> which the mnemonic is (C)hange (S)urrounding foo to bar. For example, to go from single to double ...

4

The closing angle bracket works. Do cs">.

4

The single substitution command :%s/\S\+$$\S\+$$*/'&'/g works under the assumptions different columns are separated by more than one white space and only a single space separates words within cells. It changes Foo BAR Baz Quxxx Foo Baar Asd Duxxxxx Bar Foo Baazzz Kuxx Baz Baazzz K Baz to 'Foo BAR Baz' ...

3

Change your command to use inner Word: ysiW" You might want to read the following help topic to understand better the difference between iW and aW: :h aW :h iW

3

Seems like a great job for macros. Peter Rincker's may be fewer keystrokes, but I feel it's worth mentioning as if you need a more specific range than the whole file, it's a little easier to modify. With your cursor on the first column of the first line do the following: qq to start a macro Wysiw'+ Uses ys on second WORD (Just like Peter's) and moves to ...

3

You can use :normal to run a series of normal commands on lines in the buffer. :%norm Wysiw' This will skip to the second WORD and then use surround's ys command to surround with ' on the current iw text object. It does this for every line in the buffer, %. For more help see: :h :norm :h :range

3

First of all, you need to use nmap, not nnoremap, since s is already a mapping from Surround plugin. nmap scans right side for further mappings - see :h :nmap. As of notation <M-(> - I'm not sure if it's correct. I would do it as follows (and I actually tested it like so) - while editing your .vimrc in gVim in place of <M-(> press Ctrlv and then ...

3

Well, for one it does not work very well with Repeating using .. That means, if you create a new buffer start insert mode and type (foobar your buffer will show (foobar). How redo the thing using .. It will redo only foobar. I thought it would also break the undo sequence, but that does not seem to happen. To fix the . repeating issue, I suggest to use: ...

3

You can simply unmap it just as any other mapping in Vim. But if doing this from vimrc you have to delay the unmap until the plugin was actually loaded. If using Vim8 builtin :h packages that happens after your vimrc has been processed. Therefore some additional steps must be taken. The rest is how to deal with this particular problem. There are several ...

3

Faster than visual mode: ysl" You can use both text-objects and motions with any operator, and hjkl are motions! Note that according to :help x, the command x is equivalent to dl, while X is equivalent to dh. They have a kind of paradoxical definition that turns out to be nicely intuitive in practice. The reason they work this is both are exclusive ...

2

EDIT: Your mapping doesn't work because you are in a rare case where you want to use nmap instead of nnoremap: You want to use in a mapping an already defined mapping. Using nnoremap you said to Vim "use the default behavior of ysiW"" instead of "use the behavior defined by a plugin" If I understand your mapping correctly you want to be able to transform ...

2

I always visually select string before using surround plus I have a mapping xmap s S It saves me a key stroke while surrounding selected string so for me the sequence is: va's) [obvious explanation: "select visually everything within and with single quotes and surround selection with parentheses without adding white space"] Alternative version: va'sb

2

Unfortunately, the it text-object starts right after the opening tag with a zero-width match. The only solution I see is to visually select the lines you want with V{motion} before pressing S. It is less magical than ysit<article> but oh well…

2

Put the following in your ~/.vim/after/ftplugin/eruby.vim file: nmap <buffer> ds= ds<ds%dw The idea is we delete each surrounding in turn. First < then %. Next we remove the = and the extra space.

2

This behavior is from vim-surround. From its source code, pressing either l or \ will result in \begin. To change the default behavior, refer to :h surround-customizing. First, find the number corresponding to \. In this case, we would find it with :echo char2nr("\\"), which gives 92. Then, declare the variable corresponding to this number. In this case, ...

2

vitVS<article> seems to do what you want. v to start select mode it to select "inner tag" V to start line-wise visual mode S<article> to surround It would be better to start with line-wise visual mode, and go from there, but it changes it back to 'normal' (non-line wise) visual mode.

2

Your question is pretty hard to answer in a meaningful way because it is a very specific use case. If you can be sure that the different columns are separated by more than one white space (like in your example) you could use the following substitution commands: First use :%s/\s\{2,}/'&'/g to surround every string of two or more white spaces with quotes:...

2

This answer is based on the vis plugin. That plugin provides the ability to run ex commands on just the visually-selected text. In this case, it can be used to execute a substitute command on just the selected column of text. First visually select the column to be quoted. That is, move the cursor to the upper-left corner of the column, type Ctrl-V, then ...

2

vim-surround by tpope on github I have tried following undocumented feature of vim-surround ds<space><space> and it worked for me. This has been added in commit Support ds<space><space> (7 Aug 2015 ). This commit was added after the release of version 2.1 (2015-02-08) which is currently the newest version on vim.org. Therefore, ...

2

vi(<Esc>ds(gvhoh Breakdown: vi( selects visual region within the brackets using the surround plugin. <Esc> stops the visual selection mode. ds( deletes the surrounding brackets using the surround plugin. gv restarts visual selection mode with the most recent visual selection, however it's tripped by the now missing brackets and the selection is ...

2

I use yss more often than VS; however, even without onemore set, I get this behavior. From :help surround: In visual mode, a simple "S" with an argument wraps the selection. This is referred to as the *vS* mapping, although ordinarily there will be additional keystrokes between the v and S. In linewise visual mode, the surroundings are placed on separate ...

2

Surprisingly, this doesn't appear to have been answered before given how easy of an answer it is... The author of vim-surround, Tim Pope, wrote another plugin specifically to address the issue of . (dot-repeat) not working cleanly with operations in a couple of his plugins including vim-surround. It is vim-repeat (FYI, the other supported plugins are ...

1

I'd go for a substitution: :%s/ \+-- \+/--/gc With g flag to be executed globally on the lines (not only first occurrence per line) and c to confirm (to make sure it does not change things you did not want)

Only top voted, non community-wiki answers of a minimum length are eligible