Vim: Difference between revisions

From MTU LUG Wiki
Jump to navigation Jump to search
imported>Sjwhitak
(My original comments specific to how I was describing vim; that is, I found that basic vim really isn't faster than a GUI editor, but if you have a good set of plugins and macros, vim works great.)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[File:LearningToExit im.jpg|alt=Hacker Jeopardy question on "learning to exit _IM"|thumb|The most legendary Hacker Jeopardy goof ever (GrrCON 2022)]]

= Beginner's guide =
= Beginner's guide =
We talked about vim and how to set it up. Basically type
We talked about vim and how to set it up. Basically type
Line 7: Line 9:


and follow this. You'll learn the basic hotkeys.
and follow this. You'll learn the basic hotkeys.
{{Note|If all you're using is basic vim, it isn't the best. Vim has decreased in popularity as people move towards GUI editors and IDEs, but it still has a place due to its ubiquity in *nix systems and a requirement on systems without a GUI such as a server. Additionally, when using macros and plugins, vim really shows its power.}}
{{Note|At this point, vim is still horribly useless compared to VSCode.}}


== .vimrc file ==
== .vimrc file ==
Line 36: Line 38:
Line <code>5</code> sets backspace to delete lines nicely instead of moving backwards.
Line <code>5</code> sets backspace to delete lines nicely instead of moving backwards.


{{Note|Type <code>:set</code> to view all the possible settings, and type <code>:help <setting></code> to get more information on specific settings.}}
{{Note|Again, vim is still horribly useless compared to VSCode.}}


== Plugins ==
== Plugins ==

Latest revision as of 21:19, 16 July 2024

Hacker Jeopardy question on "learning to exit _IM"
The most legendary Hacker Jeopardy goof ever (GrrCON 2022)

Beginner's guide

We talked about vim and how to set it up. Basically type

vimtutor

and follow this. You'll learn the basic hotkeys.

Note
If all you're using is basic vim, it isn't the best. Vim has decreased in popularity as people move towards GUI editors and IDEs, but it still has a place due to its ubiquity in *nix systems and a requirement on systems without a GUI such as a server. Additionally, when using macros and plugins, vim really shows its power.

.vimrc file

To edit the defaults file:

vim ~/.vimrc

You can add the following to this file:

syntax on
set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent
set number nu relativenumber
set incsearch wildmenu
set backspace=indent,eol,start

Inside vim, typing :source ~/.vimrc will adjust these defaults.

Line 1 gives syntax coloring for each file.

Line 2 sets an autoindenting where tab will be replaced with 4 spaces, and backspacing will remove 4 spaces. The smarttab will auto-indent when writing for loops, and autoindent will keep the new line's tab spacing.

Line 3 gives line numbers on the left side of vim. relativenumber gives a relative distance between each line which is beneficial for commands like j and k to go up N lines easily.

Line 4 works with searching in files. incsearch will jump to the first instance immediately while typing. wildmenu shows the files while trying to :edit <file> or :split <file>.

Line 5 sets backspace to delete lines nicely instead of moving backwards.

Note
Type :set to view all the possible settings, and type :help <setting> to get more information on specific settings.

Plugins

Plugins are the only point at which vim is more usable than VSCode. I use vim-plug and the install steps are a single line.

At this point, add these lines to your .vimrc:

call plug#begin('~/.vim/autoload')
Plug 'scrooloose/nerdtree'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
call plug#end()
let g:airline_theme='deus'
nmap <F2> :NERDTreeToggle<CR>

which will set up 3 plugins.

Nerdtree gives a nice directory on the left side of your editor. Airline and themes give