Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
9

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 ...


7

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 ...


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' ...


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 ...


5

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 ...


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">.


3

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

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 ...


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

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 (...


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: ...


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

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

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

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, ...


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)


1

There is a plugin name NerdCommenter provide many ways of commenting, includes /* */: https://github.com/scrooloose/nerdcommenter If you just need a quick solution, here is the macro which does the trick: Update: let @j="viws/*<esc>pa */<esc>" Let save it to your .vimrc file then using by moving the cursor at the word then @j.


1

Ideally, I would have a better method that would do inner word. You can do that with :normal. :%norm ysiW' I assume you want an inner WORD not word. You can also visually select the lines and then do: :norm ysiW' For more help see: :h :norm :h :range


1

In my opinion the best way to do what you want is to use a substitution command: :'<,'>s/[^ ]\+/'\0' Which is decomposed like this: '<,'> the range of lines you want to treat (you could use % is you want to change all the lines of the buffer, or use line numbers e.g. 1,10) s/ the substitution command ...


1

I have this in my .vimrc: map S ysiw Mnemonic: "you surround in word". Since this is by far my most used scenario for surround capitol S seemed like a good shortcut. :help surround does definitly help you with more examples.


1

Discl.: This is not a Surround answer, just (three into) one that give(s) the result your are expecting -- note: there is a big limitation, Surround can work with any tag, here you'll have to known your tags in advance (well, lh-brackets could ask for the tag to insert, but that wouldn't be very ergonomic) . With lh-brackets, it'll be solved with: :...


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