Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use vim profile in linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use the vim configuration file in linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

This vim configuration has the following advantages:

1. Press F5 to compile and execute C, C++, java code and shell script directly, and press "F8" to debug C, C++ code.

2. Insert the file header automatically, and insert the header automatically when you create a new C or C++ source file: including the file name, author, contact information, establishment time, etc. Readers can change them according to their needs.

3. Map "Ctrl + A" to select all and copy shortcut keys, which is convenient

4. Press "F2" to eliminate the blank lines in the code directly.

5, "F3" can list the current directory files and open the tree file directory

6, support mouse selection and arrow key movement

7, code highlighting, automatic indentation, display line number, display status line

8. Press "Ctrl + P" to complete automatically.

9, [], {}, (), "",'', etc.

10, readers of other functions can study the following files

Copy the following code directly to the text file, then rename the file to ".vimrc" (don't forget the previous "."), and then put the file under the root of the user's folder.

Reopen vim to see the effect.

To facilitate management, the source code is hosted to github, and a lot of new features are added later

Screenshot of vim configuration on github:

The following is a compact, plug-in-free vim configuration file that can be used by saving to your own .vimrc file.

The code is as follows:

"

"Show correlation

"

When "set shortmess=atI" is launched, it does not display the prompt to assist Ugandan children.

"winpos 5 5" sets window position

"set lines=40 columns=155" sets the window size

"set nu" displays the line number

Set go= "No graphics buttons

"color asmanian2" sets the background theme

Set guifont=Courier_New:h20:cANSI "set font

"syntax on" syntax highlights

Autocmd InsertLeave * se nocul "highlights the current line in a light color

Autocmd InsertEnter * se cul "highlights the current line in a light color

"set ruler" display ruler

The command entered by "set showcmd" is displayed, so you can see it clearly.

Height of the "set cmdheight=1" command line (under the status line), set to 1

"set whichwrap+=,h,l" allows backspace and cursor keys to cross line boundaries (not recommended)

Keep 3 lines apart as the "set scrolloff=3" cursor moves to the top and bottom of the buffer

"set novisualbell" Don't flicker (don't understand)

Set statusline=%F%m%r%h%w\ [FORMAT=% {& ff}]\ [TYPE=%Y]\ [POS=%l,%v] [% p%%]\% {strftime (\ "% d/%m/%y\ -\% HGV% M\")} "content displayed on the status line

Set laststatus=1 "starts to display the status line (1), and always displays the status line (2)

Set foldenable "allows folding

Set foldmethod=manual "manual folding

"set background=dark" background uses black

Set nocompatible "removes annoying vi consistency patterns and avoids some of the bug and limitations of previous versions

"Show Chinese help

If version > = 603

Set helplang=cn

Set encoding=utf-8

Endif

"set up the color scheme

"colorscheme murphy

"Font

"if (has (" gui_running "))

"set guifont=Bitstream\ Vera\ Sans\ Mono\ 10

"endif

Set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936

Set termencoding=utf-8

Set encoding=utf-8

Set fileencodings=ucs-bom,utf-8,cp936

Set fileencoding=utf-8

"

"New document title"

"create a new .c, .h, .sh, .java file and automatically insert the file header

Autocmd BufNewFile * .cpp,*. [ch], * .sh,*.java exec ": call SetTitle ()"

"" defines the function SetTitle, which automatically inserts the file header

Func SetTitle ()

"if the file type is .sh file

If & filetype = = 'sh'

Call setline (1, "\ #")

Call append (line ("."), "\ # File Name:" .clients ("%"))

Call append (line (".") + 1, "\ # Author: test")

Call append (line (".") + 2, "\ # mail: test@jbxue.com")

Call append (line (".") + 3, "\ # Created Time:" .strftime ("% c"))

Call append (line (".") + 4, "\ #")

Call append (line (".") + 5, "\ #! / bin/bash")

Call append (line (".") + 6, ")

Else

Call setline (1, "/ *)

Call append (line ("."), "> File Name:" .clients ("%"))

Call append (line (".") + 1, "> Author: test")

Call append (line (".") + 2, "> Mail: test@jbxue.com")

Call append (line (".") + 3, "> Created Time:" .strftime ("% c"))

Call append (line (".") + 4, "* * /")

Call append (line (".") + 5, "")

Endif

If & filetype = = 'cpp'

Call append (line (".") + 6, "# include")

Call append (line (".") + 7, "using namespace std;")

Call append (line (".") + 8, "")

Endif

If & filetype = ='c'

Call append (line (".") + 6, "# include")

Call append (line (".") + 7, "")

Endif

"after creating a new file, automatically navigate to the end of the file

Autocmd BufNewFile * normal G

Endfunc

"

"Keyboard command

"

Nmap w: w!

Nmap f: find

"Map all + copy ctrl+a

Map ggVGY

Map! GgVGY

Map gg=G

"Ctrl+c replication when selected

Vmap "+ y

"go to the empty line.

Nnoremap: G / ^\ s salary

"compare files

Nnoremap: vert diffsplit

"New label

Map: tabnew

"list current directory files

Map: tabnew.

"Open the tree file directory

Map\ be

"Cperfine Crunch + Press F5 to compile and run

Map: call CompileRunGcc ()

Func! CompileRunGcc ()

Exec "w"

If & filetype = ='c'

Exec "! Gmail +%-o%

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report