How can I quickly quote/unquote words and change quoting (e.g. from '
to "
) in Vim? I know about the surround.vim plugin, but I would like to use just Vim.
相关问题
- Emacs shell: save commit message
- How to change the first two uppercase characters o
- Insert text into current buffer from function
- Hot reload on save
- Substituting zero-width match in vim script
相关文章
- 如何让 vim 支持 .cshtml 文件的代码高亮
- Auto-save in VIM as you type
- How can I use gcc's -I command to add recursiv
- Vim: overloaded mapping for multiple modes
- How to use relative line numbering universally in
- How to copy the value of a vim option to a registe
- E185: Cannot find color scheme*
- How do I fix vim to properly indent folds containi
VIM for vscode does it awsomely. It's based one vim-surround if you don't use vscode.
Here's some mapping that could help:
If you haven't changed the mapleader variable, then activate the mapping with
\q"
\q'
or\qd
. They add double quote around the word under the cursor, single quote around the word under the cursor, delete any quotes around the word under the cursor respectively.To wrap in single quotes (for example)
ciw'<C-r>"'<esc>
works, but repeat won't work. Try:This puts the contents of the default register "literally". Now you can press
.
on any word to wrap it in quotes. To learn more see:h[elp] i_ctrl-r
and more about text objects at:h text-objects
Source: http://vimcasts.org/episodes/pasting-from-insert-mode/
I wrote a script that does this:
To use, just highlight something, hit control l, and then type a character. If it's one of the characters the function knows about, it'll provide the correct terminating character. If it's not, it'll use the same character to insert on both sides.
Surround.vim can do more than just this, but this was sufficient for my needs.
In addition to the other commands, this will enclose all words in a line in double quotes (as per your comment)
or if you want to reduce the number of backslashes, you can put a
\v
(very-magic) modifier at the start of the patternI don't know any builtin vim command for this, but using
r"f'r"
to change from ' to " andr'f"r'
to change from " to ' works if you stand on the first ' or ". The commandr'
replaces whatever character is under your cursor with ', andf"
moves you forward to the next ".