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
The macro ways !
press q and q for recording into q register (we use "q" as a shortcut to remember "quotes").
press shift + b move cursor to front of current word
press i type ' (a single quotes)
press esc then press e to move to end of word
press a then press ' again to surround the word with quotes.
press esc to get into normal mode.
finally press q to record it into
q
register.How to use
You can alter
step 4
with anything you like {a line, a word until found some character, etc}.Make recorded macro persistent
save and quit
open your files, go to some words
@q
if you do it correctly, magic things should appear in your words.
You can do this steps for other macros you loved.
Adding Quotes
I started using this quick and dirty function in my
.vimrc
:So now, I visually select whatever I want (typically via
viw
- visually select inside word) in quotes and press Q for double quotes, or press q for single quotes.Removing Quotes
I use vim-textobj-quotes so that vim treats quotes as a text objects. This means I can do
vaq
(visually select around quotes. This finds the nearest quotes and visually selects them. (This is optional, you can just do something likef"vww
). Then I presss
to strip the quotes from the selection.Changing Quotes
KISS. I remove quotes then add quotes. For example, to replace single quotes with double quotes, I would perform the steps: 1. remove single quotes:
vaqs
, 2. add new quotes:vwQ
.Here are some simple mappings that can be used to quote and unquote a word: