Wednesday, July 3, 2013

Work notes; vim macros and mappings

Multiline capability for GVim

"Instead you can use \_., which means "match any single character including newline". It's a bit shorter than what you have. See :h /\_.."
/This\_.*text/
http://stackoverflow.com/questions/784176/multi-line-regex-support-in-vim

How to use vim registers?

Great reference on what registers are and how to use them. http://stackoverflow.com/questions/1497958/how-to-use-vim-registers

vim clear last search highlighting

    :let @/ = ""
http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting

Multiple search and replace in one line

There are a couple ways of doing multiple commands

one

:%s/aaa/bbb/e | %s/111/222/e

two (<CR> represents actual carriage returns)

:%s/aaa/bbb/e<CR>%s/111/222/e
http://stackoverflow.com/questions/4737099/multiple-search-and-replace-in-one-line

Vim: Visual mode maps

There is a lot more in the web references, but here are some of the examples.
:vnoremap g/ y/<C-R>"<CR>
:vnoremap qq <Esc>`>a'<Esc>`<i'<Esc>
View all current mappings
:vmap
Remove a mapping
:vunmap g/
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_%28Part_1%29#Visual_mode_maps

Deselecting matching strings after search-and-replace in Vim

Stumbled upon command to turn highlighting on/off. Will remove highlighting from the current search. Highlighting will return on your next search.
:nohlsearch 
Will disable highlighting for your current vim session.
:set nohlsearch
Will clear the search pattern register (so that n etc. won't work).
:let @/="" 
http://stackoverflow.com/questions/10499866/deselecting-matching-strings-after-search-and-replace-in-vim

Write your own Vim function

function! JournalBasicConversion(...)
  :%s/^}}/ç/g
  :%s/\n{{\(\([\r\n]\+[^ç]\+.*\)\+\)\nç/\r<pre class=\"code\">\1\r<\/pre>/eg
  :%s/^==\+ \(.\+\)$/<h3>\1<\/h3>/eg
  :%s/^\[\([^\]]\+\)\]$/<a href=\"\1\" target=\"_new\">\1<\/a>/eg
  :%s/>\n\n/>\r<br \/>\r\r/eg
endfunction
http://vim.wikia.com/wiki/Write_your_own_Vim_function

Multiline capability for GVim

"Instead you can use \_., which means "match any single character including newline". It's a bit shorter than what you have. See :h /\_.."
/This\_.*text/
http://stackoverflow.com/questions/784176/multi-line-regex-support-in-vim

How to use vim registers?

Great reference on what registers are and how to use them. http://stackoverflow.com/questions/1497958/how-to-use-vim-registers

vim clear last search highlighting

    :let @/ = ""
http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting

Multiple search and replace in one line

There are a couple ways of doing multiple commands one
:%s/aaa/bbb/e | %s/111/222/e
two (<CR> represents actual carriage returns)
:%s/aaa/bbb/e<CR>%s/111/222/e
http://stackoverflow.com/questions/4737099/multiple-search-and-replace-in-one-line

Vim: Visual mode maps

There is a lot more in the web references, but here are some of the examples.
:vnoremap g/ y/<C-R>"<CR>
:vnoremap qq <Esc>`>a'<Esc>`<i'<Esc>
View all current mappings
:vmap
Remove a mapping
:vunmap g/
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_%28Part_1%29#Visual_mode_maps

Deselecting matching strings after search-and-replace in Vim

Stumbled upon command to turn highlighting on/off. Will remove highlighting from the current search. Highlighting will return on your next search.
:nohlsearch 
Will disable highlighting for your current vim session.
:set nohlsearch
Will clear the search pattern register (so that n etc. won't work).
:let @/="" 
http://stackoverflow.com/questions/10499866/deselecting-matching-strings-after-search-and-replace-in-vim

When doing a search/replace on a visual selection, how can I keep the selection?

Great summary on how selections work in Vim.
  1. Run gv to reselect the visual area, and use : from there.
  2. Use the special visual range notation * as a shortcut. For example, you can run :*s/in/out/g to run a substitution on the lines of the previous visual area.
gv

:*s/in/out/g
http://www.reddit.com/r/vim/comments/1ghqng/when_doing_a_searchreplace_on_a_visual_selection/

Search and replace in a visual selection

"The substitute command (:s) applies to whole lines, however the \%V atom will restrict a pattern so that it matches only inside the visual selection. This works with characterwise and blockwise selection (and is not needed with linewise selection). "

http://vim.wikia.com/wiki/Search_and_replace_in_a_visual_selection

Scripting common tasks in Vim

Looks interesting...

"Here you can find a bunch of useful macros, also I recommend you to learn well the useful q macro recording command, it's very very powerful..."

http://stackoverflow.com/questions/255624/scripting-common-tasks-in-vim

VIM: how to execute content of the buffer?

This led me in the right direction to better understand macros, buffers and their relationship to one another.

http://stackoverflow.com/questions/5326430/vim-how-to-execute-content-of-the-buffer

CSS Gradient Background Maker

Wonderful resource to create gradients; many versions to support different browsers.

http://ie.microsoft.com/testdrive/graphics/cssgradientbackgroundmaker/

When doing a search/replace on a visual selection, how can I keep the selection?

Great summary on how selections work in Vim.
  1. Run gv to reselect the visual area, and use : from there.
  2. Use the special visual range notation * as a shortcut. For example, you can run :*s/in/out/g to run a substitution on the lines of the previous visual area.
gv

:*s/in/out/g
http://www.reddit.com/r/vim/comments/1ghqng/when_doing_a_searchreplace_on_a_visual_selection/

Search and replace in a visual selection

"The substitute command (:s) applies to whole lines, however the \%V atom will restrict a pattern so that it matches only inside the visual selection. This works with characterwise and blockwise selection (and is not needed with linewise selection). "

http://vim.wikia.com/wiki/Search_and_replace_in_a_visual_selection

Scripting common tasks in Vim

Looks interesting...

"Here you can find a bunch of useful macros, also I recommend you to learn well the useful q macro recording command, it's very very powerful..."

http://stackoverflow.com/questions/255624/scripting-common-tasks-in-vim

VIM: how to execute content of the buffer?

This led me in the right direction to better understand macros, buffers and their relationship to one another.

http://stackoverflow.com/questions/5326430/vim-how-to-execute-content-of-the-buffer

CSS Gradient Background Maker

Wonderful resource to create gradients; many versions to support different browsers.

http://ie.microsoft.com/testdrive/graphics/cssgradientbackgroundmaker/

No comments:

Post a Comment