Skip to main content
replaced http://vi.stackexchange.com/ with https://vi.stackexchange.com/
Source Link

Unified answer:

If you are using tabs

I'd try using listchars:

:set listchars=tab:\|\ 
:set list

note: there is a space after the last \ above.

This method is good because it uses Vim's built-in support for showing this kind of thing.

Example output:

|       if (1) {
|       |       func();
|       }

screenshot of text sample above

However, this doesn't work for leading spaces. As pointed out by @Josh Petrie, there is a patch to work for spaces, but then you'd have to recompile Vim, which is beyond the scope of this answer.

If you are using spaces, and don't mind using a plugin

Vaibhav Sagar points out the plugin indentLine performs this functionality.

Install in the normal way (see installing Pluginsinstalling Plugins) and it seems to magically just work without further input. If you don't mind the ASCII bars, you don't need to do anything with your fonts. Example output of your example after setting your indentation settings and running :IndentLinesReset

45   ¦ var move = function(direction) {
46   ¦ ¦ if(!initialized) { initialize(); }
47 
48   ¦ ¦ if(shiftBoard(direction)) {
49   ¦ ¦ ¦ setTimeout(addRandomPiece, 100);
50   ¦ ¦ }
51   ¦ };

screenshot of example with spaces

The plugin requires Vim 7.3 or later, and makes cleaver use of that version's Conceal feature. Instead of actually hiding text, it replaces text with bars in the view, but not the actual buffer. The result is you see the bars but they don't get saved into the file (since they are actually spaces)

Caveat

Both of these methods assume "properly" indented code. They don't place the indentation lines at the level of indent when a "block" is opened (which sublime appears to do) but instead places lines at regular intervals based on your indentation settings. Additionally, it only shows the bars on lines where there is actually space (which is why the line in the vim output under the first if has no bars, making a visual gap)

Unified answer:

If you are using tabs

I'd try using listchars:

:set listchars=tab:\|\ 
:set list

note: there is a space after the last \ above.

This method is good because it uses Vim's built-in support for showing this kind of thing.

Example output:

|       if (1) {
|       |       func();
|       }

screenshot of text sample above

However, this doesn't work for leading spaces. As pointed out by @Josh Petrie, there is a patch to work for spaces, but then you'd have to recompile Vim, which is beyond the scope of this answer.

If you are using spaces, and don't mind using a plugin

Vaibhav Sagar points out the plugin indentLine performs this functionality.

Install in the normal way (see installing Plugins) and it seems to magically just work without further input. If you don't mind the ASCII bars, you don't need to do anything with your fonts. Example output of your example after setting your indentation settings and running :IndentLinesReset

45   ¦ var move = function(direction) {
46   ¦ ¦ if(!initialized) { initialize(); }
47 
48   ¦ ¦ if(shiftBoard(direction)) {
49   ¦ ¦ ¦ setTimeout(addRandomPiece, 100);
50   ¦ ¦ }
51   ¦ };

screenshot of example with spaces

The plugin requires Vim 7.3 or later, and makes cleaver use of that version's Conceal feature. Instead of actually hiding text, it replaces text with bars in the view, but not the actual buffer. The result is you see the bars but they don't get saved into the file (since they are actually spaces)

Caveat

Both of these methods assume "properly" indented code. They don't place the indentation lines at the level of indent when a "block" is opened (which sublime appears to do) but instead places lines at regular intervals based on your indentation settings. Additionally, it only shows the bars on lines where there is actually space (which is why the line in the vim output under the first if has no bars, making a visual gap)

Unified answer:

If you are using tabs

I'd try using listchars:

:set listchars=tab:\|\ 
:set list

note: there is a space after the last \ above.

This method is good because it uses Vim's built-in support for showing this kind of thing.

Example output:

|       if (1) {
|       |       func();
|       }

screenshot of text sample above

However, this doesn't work for leading spaces. As pointed out by @Josh Petrie, there is a patch to work for spaces, but then you'd have to recompile Vim, which is beyond the scope of this answer.

If you are using spaces, and don't mind using a plugin

Vaibhav Sagar points out the plugin indentLine performs this functionality.

Install in the normal way (see installing Plugins) and it seems to magically just work without further input. If you don't mind the ASCII bars, you don't need to do anything with your fonts. Example output of your example after setting your indentation settings and running :IndentLinesReset

45   ¦ var move = function(direction) {
46   ¦ ¦ if(!initialized) { initialize(); }
47 
48   ¦ ¦ if(shiftBoard(direction)) {
49   ¦ ¦ ¦ setTimeout(addRandomPiece, 100);
50   ¦ ¦ }
51   ¦ };

screenshot of example with spaces

The plugin requires Vim 7.3 or later, and makes cleaver use of that version's Conceal feature. Instead of actually hiding text, it replaces text with bars in the view, but not the actual buffer. The result is you see the bars but they don't get saved into the file (since they are actually spaces)

Caveat

Both of these methods assume "properly" indented code. They don't place the indentation lines at the level of indent when a "block" is opened (which sublime appears to do) but instead places lines at regular intervals based on your indentation settings. Additionally, it only shows the bars on lines where there is actually space (which is why the line in the vim output under the first if has no bars, making a visual gap)

added link to mailing list discussion of spaces patch
Source Link
user72
user72

Unified answer:

If you are using tabs

I'd try using listchars:

:set listchars=tab:\|\ 
:set list

note: there is a space after the last \ above.

This method is good because it uses Vim's built-in support for showing this kind of thing.

Example output:

|       if (1) {
|       |       func();
|       }

screenshot of text sample above

However, this doesn't work for leading spaces. As pointed out by @ Josh@Josh Petrie, there is a patch to work for spacesthere is a patch to work for spaces, but then you'd have to recompile Vim, which is beyond the scope of this answer.

If you are using spaces, and don't mind using a plugin

Vaibhav Sagar points out the plugin indentLine performs this functionality.

Install in the normal way (see installing Plugins) and it seems to magically just work without further input. If you don't mind the ASCII bars, you don't need to do anything with your fonts. Example output of your example after setting your indentation settings and running :IndentLinesReset

45   ¦ var move = function(direction) {
46   ¦ ¦ if(!initialized) { initialize(); }
47 
48   ¦ ¦ if(shiftBoard(direction)) {
49   ¦ ¦ ¦ setTimeout(addRandomPiece, 100);
50   ¦ ¦ }
51   ¦ };

screenshot of example with spaces

The plugin requires Vim 7.3 or later, and makes cleaver use of that version's Conceal feature. Instead of actually hiding text, it replaces text with bars in the view, but not the actual buffer. The result is you see the bars but they don't get saved into the file (since they are actually spaces)

Caveat

Both of these methods assume "properly" indented code. They don't place the indentation lines at the level of indent when a "block" is opened (which sublime appears to do) but instead places lines at regular intervals based on your indentation settings. Additionally, it only shows the bars on lines where there is actually space (which is why the line in the vim output under the first if has no bars, making a visual gap)

Unified answer:

If you are using tabs

I'd try using listchars:

:set listchars=tab:\|\ 
:set list

note: there is a space after the last \ above.

This method is good because it uses Vim's built-in support for showing this kind of thing.

Example output:

|       if (1) {
|       |       func();
|       }

screenshot of text sample above

However, this doesn't work for leading spaces. As pointed out by @ Josh Petrie, there is a patch to work for spaces, but then you'd have to recompile Vim, which is beyond the scope of this answer.

If you are using spaces, and don't mind using a plugin

Vaibhav Sagar points out the plugin indentLine performs this functionality.

Install in the normal way (see installing Plugins) and it seems to magically just work without further input. If you don't mind the ASCII bars, you don't need to do anything with your fonts. Example output of your example after setting your indentation settings and running :IndentLinesReset

45   ¦ var move = function(direction) {
46   ¦ ¦ if(!initialized) { initialize(); }
47 
48   ¦ ¦ if(shiftBoard(direction)) {
49   ¦ ¦ ¦ setTimeout(addRandomPiece, 100);
50   ¦ ¦ }
51   ¦ };

screenshot of example with spaces

The plugin requires Vim 7.3 or later, and makes cleaver use of that version's Conceal feature. Instead of actually hiding text, it replaces text with bars in the view, but not the actual buffer. The result is you see the bars but they don't get saved into the file (since they are actually spaces)

Caveat

Both of these methods assume "properly" indented code. They don't place the indentation lines at the level of indent when a "block" is opened (which sublime appears to do) but instead places lines at regular intervals based on your indentation settings. Additionally, it only shows the bars on lines where there is actually space (which is why the line in the vim output under the first if has no bars, making a visual gap)

Unified answer:

If you are using tabs

I'd try using listchars:

:set listchars=tab:\|\ 
:set list

note: there is a space after the last \ above.

This method is good because it uses Vim's built-in support for showing this kind of thing.

Example output:

|       if (1) {
|       |       func();
|       }

screenshot of text sample above

However, this doesn't work for leading spaces. As pointed out by @Josh Petrie, there is a patch to work for spaces, but then you'd have to recompile Vim, which is beyond the scope of this answer.

If you are using spaces, and don't mind using a plugin

Vaibhav Sagar points out the plugin indentLine performs this functionality.

Install in the normal way (see installing Plugins) and it seems to magically just work without further input. If you don't mind the ASCII bars, you don't need to do anything with your fonts. Example output of your example after setting your indentation settings and running :IndentLinesReset

45   ¦ var move = function(direction) {
46   ¦ ¦ if(!initialized) { initialize(); }
47 
48   ¦ ¦ if(shiftBoard(direction)) {
49   ¦ ¦ ¦ setTimeout(addRandomPiece, 100);
50   ¦ ¦ }
51   ¦ };

screenshot of example with spaces

The plugin requires Vim 7.3 or later, and makes cleaver use of that version's Conceal feature. Instead of actually hiding text, it replaces text with bars in the view, but not the actual buffer. The result is you see the bars but they don't get saved into the file (since they are actually spaces)

Caveat

Both of these methods assume "properly" indented code. They don't place the indentation lines at the level of indent when a "block" is opened (which sublime appears to do) but instead places lines at regular intervals based on your indentation settings. Additionally, it only shows the bars on lines where there is actually space (which is why the line in the vim output under the first if has no bars, making a visual gap)

Added information from comments and other answers into a combined super answer, hopefully better answering the OP's modified question.
Source Link
John O'M.
  • 8.7k
  • 2
  • 42
  • 58

Unified answer:

If you are using tabs

I'd try using listchars:

:set listchars=tab:\|\ 
:set list

note: there is a space after the last \ above.

This method is good because it uses Vim's built-in support for showing this kind of thing.

Example output:

|       if (1) {
|       |       func();
|       }

enter image description herescreenshot of text sample above

However, this doesn't work for leading spaces. As pointed out by @ Josh Petrie, there is a patch to work for spaces, but then you'd have to recompile Vim, which is beyond the scope of this answer.

If you are using spaces, and don't mind using a plugin

Vaibhav Sagar points out the plugin indentLine performs this functionality.

Install in the normal way (see installing Plugins) and it seems to magically just work without further input. If you don't mind the ASCII bars, you don't need to do anything with your fonts. Example output of your example after setting your indentation settings and running :IndentLinesReset

45   ¦ var move = function(direction) {
46   ¦ ¦ if(!initialized) { initialize(); }
47 
48   ¦ ¦ if(shiftBoard(direction)) {
49   ¦ ¦ ¦ setTimeout(addRandomPiece, 100);
50   ¦ ¦ }
51   ¦ };

screenshot of example with spaces

The plugin requires Vim 7.3 or later, and makes cleaver use of that version's Conceal feature. Instead of actually hiding text, it replaces text with bars in the view, but not the actual buffer. The result is you see the bars but they don't get saved into the file (since they are actually spaces)

Caveat

Both of these methods assume "properly" indented code. They don't place the indentation lines at the level of indent when a "block" is opened (which sublime appears to do) but instead places lines at regular intervals based on your indentation settings. Additionally, it only shows the bars on lines where there is actually space (which is why the line in the vim output under the first if has no bars, making a visual gap)

I'd try using listchars:

:set listchars=tab:\|\ 
:set list

note: there is a space after the last \ above.

Example output:

|       if (1) {
|       |       func();
|       }

enter image description here

Unified answer:

If you are using tabs

I'd try using listchars:

:set listchars=tab:\|\ 
:set list

note: there is a space after the last \ above.

This method is good because it uses Vim's built-in support for showing this kind of thing.

Example output:

|       if (1) {
|       |       func();
|       }

screenshot of text sample above

However, this doesn't work for leading spaces. As pointed out by @ Josh Petrie, there is a patch to work for spaces, but then you'd have to recompile Vim, which is beyond the scope of this answer.

If you are using spaces, and don't mind using a plugin

Vaibhav Sagar points out the plugin indentLine performs this functionality.

Install in the normal way (see installing Plugins) and it seems to magically just work without further input. If you don't mind the ASCII bars, you don't need to do anything with your fonts. Example output of your example after setting your indentation settings and running :IndentLinesReset

45   ¦ var move = function(direction) {
46   ¦ ¦ if(!initialized) { initialize(); }
47 
48   ¦ ¦ if(shiftBoard(direction)) {
49   ¦ ¦ ¦ setTimeout(addRandomPiece, 100);
50   ¦ ¦ }
51   ¦ };

screenshot of example with spaces

The plugin requires Vim 7.3 or later, and makes cleaver use of that version's Conceal feature. Instead of actually hiding text, it replaces text with bars in the view, but not the actual buffer. The result is you see the bars but they don't get saved into the file (since they are actually spaces)

Caveat

Both of these methods assume "properly" indented code. They don't place the indentation lines at the level of indent when a "block" is opened (which sublime appears to do) but instead places lines at regular intervals based on your indentation settings. Additionally, it only shows the bars on lines where there is actually space (which is why the line in the vim output under the first if has no bars, making a visual gap)

Source Link
John O'M.
  • 8.7k
  • 2
  • 42
  • 58
Loading