Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
5.5 KiB

  1. # Vim Configuration
  2. Stock Vim is pretty boring.
  3. The good news is that Vim has a very comprehensive configuration file which
  4. allows you to tweak it to your heart's content.
  5. To make changes to Vim you simply modify the ~/.vimrc file in your home
  6. directory.
  7. By adding simple commands this file you can easily change the way your
  8. text editor looks.
  9. Neat.
  10. I attempted to create the smallest Vim configuration file which makes
  11. Vim usable enough for me to use as my daily text editor.
  12. I believe that it is important for everyone to know what their
  13. Vim configuration does.
  14. This knowledge will help ensure that you are only adding the things
  15. you want and that you can later customize it for your workflow.
  16. Although it may be tempting to download somebody else's massive Vim
  17. configuration, I argue that this can lead to problems down the road.
  18. I want to mention that I don't use Vim as my primary
  19. IDE; I only use Vim as a text editor.
  20. I tend to use JetBrains tools on larger projects since they have amazing
  21. auto complete functionality, build tools, and comprehensive error detection.
  22. There are great Vim configurations out there on the internet; however, most
  23. tend to be a bit overkill for what most people want to do.
  24. Alright, lets dive into my vim configuration!
  25. # Spell Check
  26. ```vim
  27. autocmd BufRead,BufNewFile *.md setlocal spell spelllang=en_us
  28. autocmd BufRead,BufNewFile *.txt setlocal spell spelllang=en_us
  29. ```
  30. Since I am often an atrocious speller, having basic spell check abilities in
  31. Vim is a lifesaver.
  32. It does not make sense to have spell check enabled for most files since it
  33. would light up most programming files like a Christmas tree.
  34. I have my Vim configuration set to automatically enable spell check for markdown files
  35. and basic text files.
  36. If you need spell check in other files, you can enter the command
  37. ":set spell" to enable spell check for that file.
  38. To see the spelling recommendations, type "z=" when you are over a
  39. highlighted word.
  40. # Appearance
  41. Adding colors to Vim is fun.
  42. The "syntax enable" command tells vim to highlight keywords in programming
  43. files and other structured files.
  44. ```vim
  45. syntax enable
  46. ```
  47. I would encourage everyone to look at the different color schemes available for
  48. Vim.
  49. I threw the color scheme command in a try-catch block to ensure that it does not crash
  50. Vim if you don't have the color scheme installed.
  51. By default the desert color scheme is installed; however, that is not always the
  52. case for [community created](http://vimcolors.com/) Vim color schemes.
  53. ```vim
  54. try
  55. colorscheme desert
  56. catch
  57. endtry
  58. set background=dark
  59. ```
  60. # Indentation and Tabs
  61. Having your indentation settings squared away will save you a ton of time
  62. if you are doing any programming in Vim.
  63. ```vim
  64. "copy indentation from current line when making a new line
  65. set autoindent
  66. " Smart indentation when programming: indent after {
  67. set smartindent
  68. set tabstop=4 " number of spaces per tab
  69. set expandtab " convert tabs to spaces
  70. set shiftwidth=4 " set a tab press equal to 4 spaces
  71. ```
  72. # Useful UI Tweaks
  73. These are three UI tweaks that I find really useful to have, some people may
  74. have different opinions on these.
  75. Seeing line numbers is useful since programming errors typically just
  76. tells you what line your program went up in flames.
  77. The cursor line is useful since it allows you to easily to find your place
  78. in the file -- this may be a bit too much for some people.
  79. I like to keep every line under 80 characters long for technical files,
  80. having a visual queue for this is helpful.
  81. Some people prefer to just use the auto word wrap and keep their lines as long
  82. as they like.
  83. I like to keep to the 80 character limit and explicitly choose where
  84. I cut each line.
  85. Some of my university classes mandate the 80 character limit and take
  86. points off if you don't follow it.
  87. ```vim
  88. " Set Line Numbers to show "
  89. set number
  90. " Highlights the entire current line with a underscor "
  91. set cursorline
  92. " Displays a red bar at 80 characters "
  93. set colorcolumn=80
  94. ```
  95. # Searching and Auto Complete
  96. This these configurations make searching in Vim less painful.
  97. ```vim
  98. " search as characters are entered "
  99. set incsearch
  100. " highlight matched characters "
  101. set hlsearch
  102. " Ignore case when searching "
  103. set ignorecase
  104. ```
  105. These configurations will make command completion easier by
  106. showing an auto-complete menu when you press tab.
  107. ```vim
  108. " Shows a auto complete menu when you are typing a command "
  109. set wildmenu
  110. set wildignorecase " ignore case for auto complete
  111. ```
  112. ![Vim auto complete](media/vim/commandCompletion.png)
  113. # Useful Things to Have
  114. There is nothing too earth shattering in this section, just things that
  115. might save you some time.
  116. Enabling mouse support is a really interesting configuration.
  117. When enabled, this allows you to select text and jump between different
  118. locations with your mouse.
  119. ```vim
  120. " Enables mouse support "
  121. set mouse=a
  122. "Disable ding sound on error, flashes cursor instead "
  123. set visualbell
  124. " Display ruler on bottom right -- should be there by default "
  125. set ruler
  126. " Auto updates file if an external source edits the file "
  127. set autoread
  128. " Improves performance by only redrawing screen when needed "
  129. set lazyredraw
  130. ```
  131. Setting your file format is always a good idea for compatibility.
  132. ```vim
  133. " Set utf8 as standard encoding and en_US as the standard language "
  134. set encoding=utf8
  135. " Use Unix as the standard file type "
  136. set ffs=unix,dos,mac
  137. ```
  138. # Wrapping it up
  139. I hope that this quick blog post inspired you to maintain your own Vim
  140. configuration file.
  141. You can find my current configuration files in my
  142. [random scripts repository](https://github.com/jrtechs/RandomScripts/tree/master/config).