======Applications - Text Editors - Vim - Notes======
[[http://bullium.com/support/vim.html|Vim Commands Cheat Sheet]] [[http://bullium.com/support/vim.pdf|PDF version]] \\
=====Permanently enable syntax highlighting=====
Add to ~/.vimrc:
:syntax enable
=====Set default highlighting to 'desert' in system config=====
// Tested on Ubuntu. //
echo :colorscheme desert >> /etc/vim/vimrc.local
=====Set default in system config to always show current filename=====
// Tested on Ubuntu. //
echo :set ls=2 >> /etc/vim/vimrc.local
Source[[https://www.unix.com/shell-programming-and-scripting/132512-continuously-display-file-name-vim.html|The UNIX and Linux Forums - Continuously display the file name in vim]]
=====Convert file format from DOS to UNIX=====
To UNIX:
:set ff=unix
To DOS:
:set ff=dos
Source: [[https://stackoverflow.com/questions/82726/convert-dos-line-endings-to-linux-line-endings-in-vim|stack overflow - Convert DOS line endings to Linux line endings in vim]]
=====Replace ^M line endings with UNIX line endings=====
Type:
:s/Ctrl+VCtrl+M/\r/g
The replace will then look like this:
:s/^M/\r/g
Source:[[https://www.tech-recipes.com/unix/remove-m-characters-at-end-of-lines-in-vi/|Tech Recipes - Remove ^M characters at end of lines in vi]]
=====Replace curly double-quotes=====
To replace from the current line to the end (,$):
:,$s/[Ctrl+vu201cCtrl+vu201d]/"/g
// Ctrl+vu201c means: hit Ctrl+V, enter u201c. //
So that it looks like:
:,$s/[“”]/"/g
Source:[[https://stackoverflow.com/questions/43384677/in-vim-how-do-i-efficiently-search-and-replace-and-with-normal-double-quotes|stack overflow - In Vim how do I efficiently search and replace “ and ” with normal double quotes "]]
=====Sort=====
:sort
Sort case-insensitive:
:sort i
Source: [[https://vi.stackexchange.com/questions/23148/how-to-sort-case-insensitive|Stack Exchange - How to sort case-insensitive?]]
Sort and keep unique values:
:sort u
Source: [[https://stackoverflow.com/questions/351161/removing-duplicate-rows-in-vi#351182|stack overflow - Removing duplicate rows in vi?]]
=====Update ColdFusion syntax highlighting=====
The cf.vim with syntax highlighting supplied with Vim (on OpenBSD) does not highlight cfscript files. \\
To update, replace the highlighting with the cf-utils.vim from GitHub.
- Download the last version from [[https://github.com/camgunz/cf-utils.vim|GitHub - davejlong/cf-utils.vim
]] via the "Download ZIP/TAR.GZ" button on the right.
- Unpack the archive.
- Copy the contents of the cf-utils.vim- directory to ~/.vim/:mkdir ~/.vim/ && cp -R cf-utils.vim-15088cfad92f0e01d8d6c62e8804828f5adf8bd6/* ~/.vim/
- Start vim and open a .cfm file from ~/.vim/examples/ to test.
- The code should be highlighted in colors.
=====Disable mouse support=====
// Tested on Debian 9 with VIM 8.0 with included patches: 1-197, 322, 377-378, 550. //
Disable mouse support so you can copy and paste the way I'm used to by commenting the "if has ('mouse')" statement in /usr/share/vim/vim80/defaults.vim.
Unified diff patch to do this:
--- /usr/share/vim/vim80/defaults.vim.original 2017-04-23 14:10:29.000000000 +0200
+++ /usr/share/vim/vim80/defaults.vim 2017-07-25 09:57:42.009742204 +0200
@@ -66,9 +66,9 @@
" In many terminal emulators the mouse works just fine. By enabling it you
" can position the cursor, Visually select and scroll with the mouse.
-if has('mouse')
- set mouse=a
-endif
+"if has('mouse')
+" set mouse=a
+"endif
" Switch syntax highlighting on when the terminal has colors or when using the
" GUI (which always has colors).
Source: [[https://unix.stackexchange.com/questions/318824/vim-cutpaste-not-working-in-stretch-debian-9#318825|Stack Exchange - Unix & Linux - vim cut&paste not working in Stretch / Debian 9]]
Or just do the following which is simpler and less invasive:
echo :set mouse= >> ~/.vimrc
=====Recording=====
Start recording:q+LETTER
End recording:q
To disable recording add the following to .vimrc:map q
Source:[[https://stackoverflow.com/questions/1527784/what-is-vim-recording-and-how-can-it-be-disabled|stackoverflow - What is Vim recording and how can it be disabled?]]